-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSMSProxy.py
More file actions
46 lines (36 loc) · 1.25 KB
/
SMSProxy.py
File metadata and controls
46 lines (36 loc) · 1.25 KB
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
#!/usr/bin/env python
import ConfigParser
import os
import datetime
import web # from: http://webpy.org/
from twilio.rest import TwilioRestClient # from: https://github.com/twilio/twilio-python
config = ConfigParser.ConfigParser()
config.read(os.path.expanduser('~/SMSProxy.cfg'))
credentials = {'APP_ID': config.get("Twilio","APP_ID"), 'APP_SECRET':config.get("Twilio","APP_SECRET"), 'FROM':config.get("Twilio", "FROM")}
def valid(d, expects):
for key in expects:
if not d.has_key(key):
return False
return True
urls = (
'/', 'index',
'/sms/send', 'send'
)
app = web.application(urls, globals())
class index:
def GET(self):
return str(datetime.datetime.now())
class send:
def POST(self):
i = web.input()
client = TwilioRestClient(credentials['APP_ID'], credentials['APP_SECRET'])
return client.messages.create(to=i.To, from_=credentials['FROM'], body=i.Body)
if __name__ == "__main__":
if valid(credentials, ['APP_ID', 'APP_SECRET', 'FROM']):
app.run()
else:
print 'You need a file called ~/SMSProxy.cfg with the following contents:'
print ' [Twilio]'
print ' APP_ID=######'
print ' APP_SECRET=######'
print ' FROM=###########'