-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
42 lines (30 loc) · 1.02 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import flask
from pprint import pprint
from flask import request
app = flask.Flask(__name__)
app.config["DEBUG"] = True
@app.route('/', methods=['GET'])
def home():
return 'Welcome to PyLadies Meetup'
@app.route('/callback/ussd', methods=['POST'])
def ussd():
response = ""
text_param = request.form.get('text')
text_list = text_param.split('*')
# sessionId, phoneNumber, networkCode, serviceCode, text
# If user just dialed *384#
if not text_list[0]:
response = "CON Welcome to PyLadies banking USSD app\n"
response += "1. See your balance\n"
response += "2. Transfer money\n"
# If user selects 1 from 1st menu
elif text_list[0] == "1":
response = "END Your balance is: 0/-"
# If user selects 2 from 1st menu
elif text_list[0] == "2":
response = "CON How much do you wanna transfer?"
pprint(text_list)
if text_list[0] == "2" and len(text_list) > 1:
response = "END you have input " + text_list[1]
return response
app.run()