--- a/sms.py +++ b/sms.py @@ -1,6 +1,8 @@ import logger import argparse import datetime +import requests +import smsConf as conf parser = argparse.ArgumentParser(description="""Send sms to users whose post are published. Start and end date default to present day. @@ -17,12 +19,18 @@ posts = logger.Logger('lb_postings') -users = posts.lt.query.with_entities(posts.lt.user).filter(posts.lt.status == 3, posts.lt.posted.between(t1, t2), posts.lt.sms_sent == False) +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) users_list = [] +id_list = [] if users.count() > 0: for user in users: - users_list.append(user.user) - print users_list + sendSMS('91'+user.user, 'Hi, your recording has been successfully posted at http://cgnetswara.org/index.php?id='+user.id)) else: - print "No posts posted." + return False + + +def sendSMS(number, message): + data = {'user': conf.username, 'passwd': conf.passwd, 'message': message, 'mobilenumber':number, 'mtype':'N', 'DR':'Y'} + sms = requests.get(conf.url, params=data) + return sms