Commit 4a1fa1481beff9691f8280d23fee0032240524d6
Adding capability to send sms
-Using smscountry api to send out messages to users whose
recordings have been posted.
| | | | 1 | import logger | 1 | import logger |
---|
2 | import argparse | 2 | import argparse |
---|
3 | import datetime | 3 | import datetime |
---|
| | 4 | import requests |
---|
| | 5 | import smsConf as conf |
---|
4 | | 6 | |
---|
5 | parser = argparse.ArgumentParser(description="""Send sms to users whose post are published. | 7 | parser = argparse.ArgumentParser(description="""Send sms to users whose post are published. |
---|
6 | Start and end date default to present day. | 8 | Start and end date default to present day. |
---|
… | | … | |
---|
19 | | 19 | |
---|
20 | | 20 | |
---|
21 | posts = logger.Logger('lb_postings') | 21 | posts = logger.Logger('lb_postings') |
---|
22 | 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).filter(posts.lt.status == 3, posts.lt.posted.between(t1, t2), posts.lt.sms_sent == False) |
---|
| | 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 = [] | 23 | users_list = [] |
---|
| | 24 | id_list = [] |
---|
24 | if users.count() > 0: | 25 | if users.count() > 0: |
---|
25 | for user in users: | 26 | for user in users: |
---|
26 | users_list.append(user.user) | | users_list.append(user.user) |
---|
27 | print users_list | | print users_list |
---|
| | 27 | sendSMS('91'+user.user, 'Hi, your recording has been successfully posted at http://cgnetswara.org/index.php?id='+user.id)) | 28 | else: | 28 | else: |
---|
29 | print "No posts posted." | | print "No posts posted." |
---|
| | 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 |
---|