-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_driver.py
executable file
·62 lines (49 loc) · 1.58 KB
/
text_driver.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
import argparse
import config
from twilio.rest import Client
parser = argparse.ArgumentParser()
parser.add_argument('-r', '--recipient',
help='Key of the recipient in the \
Recipients dict, currently \
one of {"SO", "Self"}.',
type=str)
parser.add_argument('-m', '--message',
help='String message that you want \
to send. Can be a string key \
to the messages dict.',
type=str)
args = parser.parse_args()
def parse():
"""
parse()
Validate the command line args, and return the recipient phone #
and message.
Gets: nothing
Returns:
recipient, a string
message, a string
"""
if args.recipient not in config.RECIPIENTS:
raise KeyError('Recipient not in config.RECIPIENTS')
recipient = config.RECIPIENTS[args.recipient]
if args.message in config.MESSAGES:
message = config.MESSAGES[args.message]
else:
message = args.message
return recipient, message
def send(recipient, message):
"""
send(recipient, message)
Creates a Client instance and uses it to send a SMS message
Gets:
recipient, a string
message, a string
Returns: Nothing
"""
client = Client(config.SID, config.TWILIO_TOKEN)
payload = client.messages.create(body=message, from_=config.TWILIO_NUMBER, to=recipient)
def main():
recipient, message = parse()
send(recipient, message)
if __name__ == '__main__':
main()