Subversion Repositories SmartDukaan

Rev

Rev 20689 | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on Apr 28, 2015

@author: amit
'''
from dtr.main import client
from dtr.storage.Mongo import sendNotification
import sys
import getopt
import traceback
from dtr.main import tprint

mongoHost = "192.168.158.89"

def main(argv):
    #scrapepaytm()
    credittype = 'Order'
    try:
        opts, args = getopt.getopt(argv,"ht:",["credittype="])
    except getopt.GetoptError:
        print 'pushbatchcreditnotification.py -t <Order|App>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'pushbatchcreditnotification.py -t <Order|App>'
            sys.exit()
        elif opt == '-t':
            credittype = arg
            
        tprint("Sending notification", credittype)
        
        try:
            send_Notification(credittype)
        except:
            tprint("Error")
            traceback.print_exc()
    
    
def send_Notification(credittype):
    db = client.Dtr

    batchId = db.refund.find_one({"$query":{"type":credittype},"$orderby":{"batch":-1}}).get("batch")
    print "Batch Id recently Credited", batchId
    if batchId is None:
        return
    refunds = db.refund.find({"batch":batchId})
    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), '2999-01-01', True, "TRAN_SMS Dear Customer, Cashback credited for %ss. Rs.%s has been added to your wallet"%(str(credittype),250))
    #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))
    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), '2999-01-01',True, "TRAN_SMS Dear Customer, Cashback credited for %ss. Rs.%s has been added to your wallet"%(str(credittype),250))
    for ref in refunds:
        print ref.get("userId"), ref.get("userAmount")
        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")), '2999-01-01', True, "TRAN_SMS Dear Customer, Cashback Credited for %ss. Rs.%s has been added to your wallet"%(str(credittype),int(ref.get("userAmount"))))

if __name__ == '__main__':
    main(sys.argv[1:])