Subversion Repositories SmartDukaan

Rev

Rev 16651 | Rev 17073 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16651 Rev 17072
Line 3... Line 3...
3
 
3
 
4
@author: amit
4
@author: amit
5
'''
5
'''
6
from dtr.main import client
6
from dtr.main import client
7
from dtr.utils.utils import sendNotification
7
from dtr.utils.utils import sendNotification
-
 
8
import sys
-
 
9
import getopt
-
 
10
import traceback
-
 
11
import tprint
-
 
12
 
8
def main():
13
def main(argv):
9
    #scrapepaytm()
14
    #scrapepaytm()
-
 
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):
10
    db = client.Dtr
38
    db = client.Dtr
11
 
39
 
12
    batchId = db.refund.find_one({"$query":{},"$orderby":{"batch":-1}}).get("batch")
40
    batchId = db.refund.find_one({"$query":{"type":credittype},"$orderby":{"batch":-1}}).get("batch")
13
    print "Batch Id recently Credited", batchId
41
    print "Batch Id recently Credited", batchId
14
    if batchId is None:
42
    if batchId is None:
15
        return
43
        return
16
    refunds = db.refund.find({"batch":batchId})
44
    refunds = db.refund.find({"batch":batchId})
17
    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))
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))
Line 20... Line 48...
20
        print ref.get("userId"), ref.get("userAmount")
48
        print ref.get("userId"), ref.get("userAmount")
21
        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")))
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")))
22
        pass
50
        pass
23
 
51
 
24
if __name__ == '__main__':
52
if __name__ == '__main__':
25
    main()
-
 
26
53
    main(sys.argv[1:])
-
 
54
27
55