-
Notifications
You must be signed in to change notification settings - Fork 3
/
textbelt
executable file
·38 lines (29 loc) · 1.27 KB
/
textbelt
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
#!/usr/bin/env python
import argparse
import json
import requests
TEXTBELT_URL = 'http://textbelt.com/text'
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Send SMS message')
parser.add_argument('-n', dest='phone_number', required=True,
help='phone number without punctuation, e.g., 5551234567')
parser.add_argument('-m', dest='message', required=True,
help='text of message')
parser.add_argument('-v', action='store_true', dest='verbose', default=False,
help='verbose mode')
args = parser.parse_args()
if args.verbose:
print 'sending "%s" to %s' % (args.message, args.phone_number)
data = {'message': args.message, 'number': args.phone_number}
r = requests.post(TEXTBELT_URL, data=data)
if r.ok:
content = json.loads(r.content)
if args.verbose:
print 'Message received by Textbelt with status code: %d' % r.status_code
if content['success']:
if args.verbose:
print 'Message sent to providers by Textbelt'
else:
print 'FAILURE: Message not sent to providers by Textbelt (%s)' % content['message']
else:
print 'FAILURE: Message not received by Textbelt'