#!/usr/bin/env python
from __future__ import print_function
import os
import sys

numparts = int(os.environ['DECODED_PARTS'])

# Are there any decoded parts?
if numparts == 0:
    print('No decoded parts!')
    sys.exit(1)

# Get all text parts
text = ''
for i in range(1, numparts + 1):
    varname = 'DECODED_%d_TEXT' % i
    if varname in os.environ:
        text = text + os.environ[varname]

# Do something with the text
print('Number %s have sent text: %s' % (os.environ['SMS_1_NUMBER'], text))
