-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapprunner.py
74 lines (57 loc) · 1.57 KB
/
apprunner.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
66
67
68
69
70
71
72
73
74
import time, random, logging
global twil_msg
twil_msg = 'somehit'
class AppRunner(object):
def __init__(self, Service, contacts, acked, twil_msg):
self.Service = Service
self.contacts = contacts
self.call_list = []
self.problems = []
self.acked = False
def checkprobs(self):
print "checking problems"
self.Service.check()
self.problems = self.Service.problems
if self.problems:
return self.checkacked
else:
return self.set_not_acked
def checkacked(self):
self.acked = acked
if self.acked:
return self.wait
else:
return self.makecall
def set_not_acked(self):
self.acked = False
return self.wait
def wait(self):
time.sleep(5)
return self.checkprobs
def makecall(self):
if len(self.call_list) <= 0:
self.call_list = list(self.contacts)
random.shuffle(self.call_list)
callee = self.call_list.pop()
print "contacting {} at {}".format(callee[0], callee[1]['phone'])
print "using call back", config.DOMAIN + "/gather"
self.call = client.calls.create(
to=callee[1]['phone'],
from_= config.TWILIO.CALL_FROM,
url=config.DOMAIN + "/gather",
method='GET',
status_callback=config.DOMAIN + "/end",
status_method='GET',
if_machine = 'Hangup'
)
#blocking = ['QUEUED', 'RINGING', 'IN-PROGRESS']
#return self.wait
return
def runme(self):
self.call = None
nextdo = self.checkprobs()
while True:
if hasattr(nextdo, "__call__"):
nextdo = nextdo()
else:
break