From c13be5acf8963324a91ccfc722179856e96c8b45 Mon Sep 17 00:00:00 2001 From: Sandeep Date: Tue, 21 Aug 2018 06:59:33 +0530 Subject: [PATCH 1/3] script to send sms --- requirements.txt | 1 + sms.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 sms.py diff --git a/requirements.txt b/requirements.txt index 8c9e4a91c..62b586878 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,3 +20,4 @@ pillow==5.2.0 boto3==1.7.80 botocore==1.10.80 django-storages==1.6.6 +dateutil diff --git a/sms.py b/sms.py new file mode 100644 index 000000000..8f9604212 --- /dev/null +++ b/sms.py @@ -0,0 +1,64 @@ +# Dependencies - Requests, dateutil +# Python 2.7.15 + +# Expects a csv file's path containing volunteer details + +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() From 7ee65758a87c6a779b810a1d97024798b548b706 Mon Sep 17 00:00:00 2001 From: Sandeep Date: Tue, 21 Aug 2018 07:24:25 +0530 Subject: [PATCH 2/3] script to send sms, minor fixes --- sms.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sms.py b/sms.py index 8f9604212..3e85c5eee 100644 --- a/sms.py +++ b/sms.py @@ -2,6 +2,10 @@ # 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 @@ -49,7 +53,7 @@ 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) + response = requests.get('http://api.esms.kerala.gov.in/fastclient/SMSclient.php',params=payload) except KeyboardInterrupt: From 025605e0226a2eb334d8f25842ea5b1cbce32bb9 Mon Sep 17 00:00:00 2001 From: Sandeep Date: Tue, 21 Aug 2018 15:34:08 +0530 Subject: [PATCH 3/3] fixed dependencies --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 62b586878..d5cb0b4b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ pillow==5.2.0 boto3==1.7.80 botocore==1.10.80 django-storages==1.6.6 -dateutil +python-dateutil