1
import logger
2
import argparse
3
import datetime
4
import requests
5
import smsConf as conf
6
7
parser = argparse.ArgumentParser(description="""Send sms to users whose post are published.
8
                                 Start and end date default to present day.
9
                                 Start time defaults to 00:00:00.
10
                                 End time defaults to 23:59:59.""")
11
parser.add_argument('-s','--start-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="Start date (YYYY-MM-DD)")
12
parser.add_argument('-e','--end-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="End date (YYYY-MM-DD)")
13
parser.add_argument('-S','--start-time', type=str, default = '00:00:00', help="Start time (HH:MM:SS)")
14
parser.add_argument('-E','--end-time', type=str, default='23:59:59', help="End time (HH:MM:SS)")
15
16
args = parser.parse_args()
17
t1 = args.start_date + " " + args.start_time
18
t2 = args.end_date + " " + args.end_time
19
20
21
posts = logger.Logger('lb_postings')
22
users = posts.lt.query.with_entities(posts.lt.user, posts.lt.id).filter(posts.lt.status == 3, posts.lt.posted.between(t1, t2), posts.lt.sms_sent == False)
23
users_list = []
24
id_list = []
25
if users.count() > 0:
26
    for user in users:
27
        sendSMS('91'+user.user, 'Hi, your recording has been successfully posted at http://cgnetswara.org/index.php?id='+user.id))
28
else:
29
    return False
30
31
32
def sendSMS(number, message):
33
    data = {'user': conf.username, 'passwd': conf.passwd, 'message': message, 'mobilenumber':number, 'mtype':'N', 'DR':'Y'}
34
    sms = requests.get(conf.url, params=data)
35
    return sms