Beispiel #1
0
def index():

    # Enable CORS (Cross Domain POST)
    response.headers['Access-Control-Allow-Origin'] = '*'

    ussd = at.AfricasTalkingUssd(request.POST)

    if ussd.text == "":
        # This is the first hit of the service so return the main menu
        menu,next_menu = at.make_menu('Simple USSD Test',[
            'Guess A Number',
            'Convert KSH',
            'Random Swahili Words',
            'Random Hindi Words',
            'My Phone Number'
        ])
        menu += '\n\n  - UW ICTD - '
        return ussd.con(menu)

    elif ussd.commands[0] == '1':
        return guessing_game(ussd)

    elif ussd.commands[0] == '2':
        return convert_ksh(ussd)

    elif ussd.commands[0] == '3':
        return swahili_length(ussd)

    elif ussd.commands[0] == '4':
        return hindi_length(ussd)

    elif ussd.commands[0] == '5':
        return ussd.end(ussd.phoneNumber)
Beispiel #2
0
def convert_ksh(ussd):
    # Convert KSH into other currencies
    if len(ussd.commands) == 1:
        return ussd.con('Enter amount in KSH')
    ksh = float(ussd.commands[1])

    currencies = ['USD','EUR','ZAR']
    if len(ussd.commands) == 2:
        menu,next_menu = at.make_menu('Choose A Currence',currencies)
        return ussd.con(menu)

    currency = ussd.commands[2]
    if currency.isdigit():
        currency = currencies[int(currency)-1]
    currency = currency.upper()

    conversions = {'USD':0.0098,'EUR':0.0092,'ZAR':0.14}
    converted = ksh*conversions[currency]

    return ussd.end('{0:.2f} KSH\n=\n{1:.2f} {2}\n\nThanks for using USSD Converter'.format(ksh,converted,currency))