Subversion Repositories SmartDukaan

Rev

Rev 16651 | Rev 17073 | 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
7
from dtr.utils.utils import sendNotification
17072 manish.sha 8
import sys
9
import getopt
10
import traceback
11
import tprint
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})
45
    sendNotification([8], 'Batch Credit', 'Cashback Credited', 'Rs.%s has been added to your wallet'%(250), 'url', 'http://api.profittill.com/cashbacks/mine?user_id=%s'%(8))
46
    sendNotification([14], 'Batch Credit', 'Cashback Credited', 'Rs.%s has been added to your wallet'%(250), 'url', 'http://api.profittill.com/cashbacks/mine?user_id=%s'%(14))
47
    for ref in refunds:
48
        print ref.get("userId"), ref.get("userAmount")
16651 amit.gupta 49
        sendNotification([ref.get("userId")], 'Batch Credit', 'Cashback Credited', '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")))
14995 amit.gupta 50
        pass
51
 
52
if __name__ == '__main__':
17072 manish.sha 53
    main(sys.argv[1:])