forked from pika-shi/pizza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twilio_call.py
44 lines (29 loc) · 1.17 KB
/
twilio_call.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
# -*- coding: utf-8 -*-
import urllib
import urllib2
from twilio.rest import TwilioRestClient
class TwilioCall(object):
account_sid = "*****"
auth_token = "*****"
from_phonenumber = "+81503131****"
base_url = "http://o-tomox.com/~satoshi/pizza.php"
def __init__(self):
self.client = TwilioRestClient(TwilioCall.account_sid, TwilioCall.auth_token)
def order_pizza(self, order):
params = {}
params["k"] = ",".join(map(str, order["kind_list"]))
params["s"] = ",".join(map(str, order["size_list"]))
params["n"] = ",".join(map(str, order["num_list"]))
params["t"] = str(order["dlt"])
params["name"] = urllib.quote(order["name"])
params["phonenumber"] = order["tel"]
url = "{0}?{1}".format(TwilioCall.base_url, "&".join(["{0}={1}".format(key, params[key]) for key in params]))
print url
response = urllib2.urlopen(url)
print response.read()
# call = self.client.calls.create(url=url, to="+819079383869", from_=TwilioCall.from_phonenumber)
# print call
if __name__ == '__main__':
order = {"kind_list": [3], "size_list": [35], "num_list": [1], "dlt": 60, "name": "ぴかし", "tel": "12345678"}
twilio_call = TwilioCall()
twilio_call.order_pizza(order)