From 4a1fa1481beff9691f8280d23fee0032240524d6 Mon Sep 17 00:00:00 2001 From: Arvind Date: Fri, 24 Jan 2014 19:11:18 +0530 Subject: [PATCH] Adding capability to send sms -Using smscountry api to send out messages to users whose recordings have been posted. --- sms.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sms.py b/sms.py index 6dc4d68..8c4df50 100644 --- 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,11 +19,17 @@ t2 = args.end_date + " " + args.end_time 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." \ No newline at end of file + 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 \ No newline at end of file -- 1.7.10.4