-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflaskapp.py
57 lines (49 loc) · 1.7 KB
/
flaskapp.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from flask import Flask, request, render_template
import twilio.twiml
from twilio.rest import TwilioRestClient
from time import sleep
app = Flask(__name__)
@app.route("/")
def index():
return render_template('index.html')
@app.route("/dialing", methods=['POST'])
def dial():
phone_num = "+1" + request.form['pNumber']
delay = request.form['delay']
phonebuzz_num = "+17606711394"
# Credentials
account_sid = "ACd0a9af9570cb3204b46a1c874003c045"
auth_token = "61cc15906b94828995d98e608bbfb3a9"
client = TwilioRestClient(account_sid, auth_token)
sleep(60.0 * float(delay))
# Making call
call = client.calls.create(to=phone_num, # Any phone number
from_=phonebuzz_num, # Must be a valid Twilio number
url="http://twiliofizzbuzz-ernestoeperez.rhcloud.com/play-phonebuzz")
print call.sid
@app.route("/play-phonebuzz", methods=['GET', 'POST'])
def play_phoneBuzz():
"""Respond to incoming requests."""
resp = twilio.twiml.Response()
with resp.gather(action="/handle-input", method="POST", numDigits=2) as g:
g.say("Please enter a two digit number to start playing")
return str(resp)
@app.route("/handle-input", methods=['GET', 'POST'])
def handle_input():
input_num = int(request.values.get('Digits', None))
message = ''
# FizzBuzz
for num in range(1, input_num + 1):
next = ''
if num % 3 == 0:
next += 'Fizz'
if num % 5 == 0:
next += 'Buzz'
if not next:
next = str(num)
message += next + ' '
resp = twilio.twiml.Response()
resp.say(message)
return str(resp)
if __name__ == "__main__":
app.run(debug=True)