-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms.py
43 lines (36 loc) · 1.42 KB
/
sms.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
# sms.py - Handles the Twilio messaging capabilities.
import logging
import ConfigParser
import mygps
from twilio.rest import TwilioRestClient
from twilio import TwilioRestException
config = ConfigParser.ConfigParser()
config.read('config')
client = TwilioRestClient(config.get('twilio', 'account_sid'), config.get('twilio', 'auth_token'))
# The function that uses twilio to send the car's owner a SMS
def send_text(message, temperature, delta, minutes_elapsed,
number="+17348463494"):
"""
Sends a text message to the specified number with temperature,
minutes elapsed.
"""
message += " The inside of the car is currently %d degrees, with " \
"a %d degree change in %d minutes." % (temperature,
delta, minutes_elapsed)
try:
sms = client.messages.create(body=message,
to=number,
from_=config.get('twilio', 'from_number'))
except TwilioRestException as e:
print(repr(e))
logging.error(repr(e))
def contact_911():
"""
If too much time has elapsed without any detected change in the
car, or if it becomes far too hot too quickly, get the nearest
authorities. This section left unfilled due to variences in support between
police departments.
"""
(lat, lon) = mygps.get_coords()
print lat
print lon