Skip to content

Commit

Permalink
Merge pull request #792 from sndp487/sndp487/sms_responder
Browse files Browse the repository at this point in the history
Sndp487/sms responder
  • Loading branch information
biswaz authored Aug 22, 2018
2 parents 8c3f4be + a4cc4e4 commit fa4b341
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ pillow==5.2.0
boto3==1.7.80
botocore==1.10.80
django-storages==1.6.6
python-dateutil
beautifulsoup4==4.6.3

68 changes: 68 additions & 0 deletions sms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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()

0 comments on commit fa4b341

Please sign in to comment.