Subversion Repositories SmartDukaan

Rev

Rev 17280 | Rev 18483 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14995 amit.gupta 1
'''
2
Created on Apr 28, 2015
3
 
4
@author: amit
5
'''
6
from dtr.main import client
17280 manish.sha 7
from dtr.storage.Mongo import sendNotification
17072 manish.sha 8
import sys
9
import getopt
10
import traceback
17073 manish.sha 11
from dtr.main import tprint
17072 manish.sha 12
 
13
def main(argv):
14995 amit.gupta 14
    #scrapepaytm()
17072 manish.sha 15
    credittype = 'Order'
16
    try:
17
        opts, args = getopt.getopt(argv,"ht:",["credittype="])
18
    except getopt.GetoptError:
19
        print 'pushbatchcreditnotification.py -t <Order|App>'
20
        sys.exit(2)
21
    for opt, arg in opts:
22
        if opt == '-h':
23
            print 'pushbatchcreditnotification.py -t <Order|App>'
24
            sys.exit()
25
        elif opt == '-t':
26
            credittype = arg
27
 
28
        tprint("Sending notification", credittype)
29
 
30
        try:
31
            send_Notification(credittype)
32
        except:
33
            tprint("Error")
34
            traceback.print_exc()
35
 
36
 
37
def send_Notification(credittype):
14995 amit.gupta 38
    db = client.Dtr
16651 amit.gupta 39
 
17072 manish.sha 40
    batchId = db.refund.find_one({"$query":{"type":credittype},"$orderby":{"batch":-1}}).get("batch")
16651 amit.gupta 41
    print "Batch Id recently Credited", batchId
14995 amit.gupta 42
    if batchId is None:
43
        return
44
    refunds = db.refund.find({"batch":batchId})
18384 amit.gupta 45
    #sendNotification([8], 'Batch Credit', 'Cashback Credited for %ss'%(str(credittype)), 'Rs.%s has been added to your wallet'%(250), 'url', 'http://api.profittill.com/cashbacks/mine?user_id=%s'%(8))
46
    sendNotification([8], 'Batch Credit', 'Cashback Credited for %ss'%(str(credittype)), 'Rs.%s has been added to your wallet'%(250), 'url', 'http://api.profittill.com/cashbacks/mine?user_id=%s'%(8), True, "TRAN_SMS Dear Customer, Cashback credited for %ss. Rs.%s has been added to your wallet"%(str(credittype),250))
47
    #sendNotification([14], 'Batch Credit', 'Cashback Credited for %ss'%(str(credittype)), 'Rs.%s has been added to your wallet'%(250), 'url', 'http://api.profittill.com/cashbacks/mine?user_id=%s'%(14))
48
    sendNotification([14], 'Batch Credit', 'Cashback Credited for %ss'%(str(credittype)), 'Rs.%s has been added to your wallet'%(250), 'url', 'http://api.profittill.com/cashbacks/mine?user_id=%s'%(8), True, "TRAN_SMS Dear Customer, Cashback credited for %ss. Rs.%s has been added to your wallet"%(str(credittype),250))
14995 amit.gupta 49
    for ref in refunds:
50
        print ref.get("userId"), ref.get("userAmount")
18384 amit.gupta 51
        sendNotification([ref.get("userId")], 'Batch Credit', 'Cashback Credited for %ss'%(str(credittype)), 'Rs.%s has been added to your wallet'%(int(ref.get("userAmount"))), 'url', 'http://api.profittill.com/cashbacks/mine?user_id=%s'%(ref.get("userId")), True, "TRAN_SMS Dear Customer, Cashback Credited for %ss. Rs.%s has been added to your wallet"%(str(credittype),int(ref.get("userAmount"))))
14995 amit.gupta 52
 
53
if __name__ == '__main__':
17072 manish.sha 54
    main(sys.argv[1:])