-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverping.py
84 lines (61 loc) · 1.49 KB
/
serverping.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
75
76
77
78
79
80
81
82
83
import time, random, sys, logging
from threading import Thread
# 3rd party
from twilio.rest import TwilioRestClient
from twilio import twiml
from bottle import route, run
# Internal libs
import config
global config
from config_tools import namedtupify
from service import ServerPing
from webface import *
from apprunner import AppRunner
config.TWILIO = namedtupify('Config', config.TWILIO)
client = TwilioRestClient(
config.TWILIO.ACCOUNT_SID, config.TWILIO.AUTH_TOKEN)
@route('/')
def index():
global twil_msg
return twil_msg
@route('/gather')
def gather():
global twil_msg
press1 = " To acknowledge this message press 1 and then the # now."
twil_msg += press1
r = twiml.Response()
r.say(twil_msg)
r.gather(action=config.DOMAIN + '/ack', finishOnKey="#", method="GET")
#r.redirect(config.DOMAIN + '/ack')
return str(r)
@route('/ack')
def ackdo():
global acked
acked = True
r = twiml.Response()
r.say('Thank you and good bye.')
r.hangup()
return str(r)
@route('/end')
def ending():
sys.exit()
@route('/fail')
def callfail():
# release lock here
pass
def bottlerunner():
run(host='localhost', port=8080)
if __name__ == '__main__':
global twil_msg
twil_msg = "starting up"
global acked
acked = False
pingapp = AppRunner(ServerPing, config.CONTACTS, acked, twil_msg)
pingapp.checkprobs()
print pingapp.Service.msg
m = Thread(target=bottlerunner())
m.daemon = True
m.start()
#s = Thread(target=pingapp.runme())
#s.daemon = True
#s.start()