Esempio n. 1
0
    char_count = int(ussd.last)

    if char_count <= 0:
        response_str = '\n'.join(['{0}. Chars {1}'.format(i+1,c) for i,c in enumerate(ussd.commands[1:])])
        response_str += '\n\n -- {} hops --'.format(len(ussd.commands))
        return ussd.end(response_str)

    response_str = ''
    while True:
        missing = char_count - len(response_str)
        if str(missing) in words.keys():
            response_str += random.choice(words[str(missing)])
            break
        elif len(response_str) > char_count:
            response_str = response_str[:char_count]
            break
        else:
            response_str += random.choice(words[random.choice(words.keys())]) + ' '

    return ussd.con(response_str)

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-p','--port',default=8080,type=int,help='port to run on. default = 8080')
    parser.add_argument('-r','--reloader',default=False,action='store_true',help='run with reloader on. default = False')
    parser.add_argument('-d','--no-debug',dest='debug',default=True,action='store_false',help='run in debug mode. default = True')
    options = parser.parse_args()
    print options

    app.run(host="0.0.0.0",port=options.port,debug=options.debug,reloader=options.reloader)
Esempio n. 2
0
from libs.bottle import Bottle, static_file, response
from AfricasTalkingUssd import enable_cors

client = Bottle()

@client.route('/')
@enable_cors
def test():
    return static_file('test.html',root='static')

static = Bottle()
@static.route('/<filename>')
def static_server(filename):
    return static_file(filename,root='static')

client.mount('/static',static)

if __name__ == '__main__':
    client.run(host='localhost',port='4040',debug=True,reloader=True)