forked from raksha-life/rescuekerala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms.py
68 lines (47 loc) · 1.45 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
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
# Dependencies - Requests, dateutil
# Python 2.7.15
# Expects a csv file's path containing volunteer details
# Fill in the credentials in line 55, and run the script
# Example usage:
# python2 path/to/sms.py path/to/csvFile.csv
import calendar
import csv
import datetime
import sys
import time
import requests
from dateutil import parser
csvFile = sys.argv[1] #command line argument
if __name__ == "__main__":
# csv file path not provided
if len(sys.argv) < 1:
sys.exit()
#stores failed sms
failed = open("Failed",'w')
fin = open(csvFile,'r')
# to avoid multiple sms to same mobile number
mark = {}
for fields in csv.reader(fin):
sendID = fields[0]
timestamp = fields[8]
mobile = fields[3]
if mobile in mark:
continue
mark[mobile]=1
if mobile.isdigit():
try:
# Converting timestamp to epoch
timestamp = parser.parse(timestamp)
timestamp = calendar.timegm(timestamp.utctimetuple())
# Preparing unique URL
url = 'http://keralarescue.in/c/' + sendID + "/" + str(timestamp)[-4:]
message = "Thank you for registering to volunteer. Please click here to confirm " + url
payload = { 'username':'xxxxxxxx','password':'xxxxxxxx','message':message,'numbers':mobile}
response = requests.get('http://api.esms.kerala.gov.in/fastclient/SMSclient.php',params=payload)
except KeyboardInterrupt:
failed.write(mobile)
sys.exit()
except:
failed.write(mobile)
fin.close()
failed.close()