-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcgi.py
65 lines (52 loc) · 1.78 KB
/
cgi.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
58
59
60
61
62
63
64
65
import os, sys
import web
import simplejson
path = os.path.dirname(__file__)
sys.path.append("%s/" %path)
import valentunes
import config
urls = (
'/call', 'Call',
'/change', 'Change',
)
class Change:
def GET(self):
args = web.input()
## Check required parameters
if '_uid' not in args.keys():
return "_uid parameter required (user ID)"
## Go !
switch = valentunes.Switcher(args)
return switch.go()
class Call:
def POST(self):
args = web.input()
## Get data
if 'data' in args.keys():
## Parse JSON
data = simplejson.loads(args['data'])
## Required parameters
if 'to' not in data.keys():
return "to parameter required (name of the person you want to call)"
_to = data['to']
if 'from' not in data.keys():
return "from parameter required (your name)"
_from = data['from']
if 'phone' not in data.keys():
return "phone parameter required (phone number to ring)"
_phone = data['phone']
if 'songs' not in data.keys():
return "songs parameter required (list of songs)"
_songs = data['songs']
## Additional parameters
_message = ''
if 'message' in data.keys():
_message = data['message']
_voice = 'man'
if 'voice' in data.keys():
_voice = data['voice']
## Go !
return valentunes.Valentunes(_phone, _songs, _from, _to, message = _message, voice = _voice).call()
else:
return "KO"
application = web.application(urls, globals()).wsgifunc()