Subversion Repositories SmartDukaan

Rev

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

Rev 16727 Rev 16739
Line 5... Line 5...
5
import getopt
5
import getopt
6
from dtr.main import tprint, refundToWallet
6
from dtr.main import tprint, refundToWallet
7
import time
7
import time
8
from dtr.storage import DataService
8
from dtr.storage import DataService
9
from elixir import *
9
from elixir import *
-
 
10
import pymongo
-
 
11
from dtr.utils import utils
10
 
12
 
11
DataService.initialize(db_hostname="localhost") 
13
DataService.initialize(db_hostname="localhost") 
-
 
14
con=None
-
 
15
 
-
 
16
def get_mongo_connection(host='localhost', port=27017):
-
 
17
    global con
-
 
18
    if con is None:
-
 
19
        print "Establishing connection %s host and port %d" %(host,port)
-
 
20
        try:
-
 
21
            con = pymongo.MongoClient(host, port)
-
 
22
        except Exception, e:
-
 
23
            print e
-
 
24
            return None
-
 
25
    return con
12
 
26
 
13
def settleAppOffersPayBack(runtype='dry'):
27
def settleAppOffersPayBack(runtype='dry'):
14
    if runtype == 'live':
28
    if runtype == 'live':
15
        currentTimestamp = datetime.today()
29
        currentTimestamp = datetime.today()
16
        currentMonth = currentTimestamp.month
30
        currentMonth = currentTimestamp.month
Line 27... Line 41...
27
                    userCashbacksMap[userCashback.user_id] = cashBackAmount
41
                    userCashbacksMap[userCashback.user_id] = cashBackAmount
28
                else:
42
                else:
29
                    userCashbacksMap[userCashback.user_id] = userCashback.amount
43
                    userCashbacksMap[userCashback.user_id] = userCashback.amount
30
        datetimeNow = datetime.now() 
44
        datetimeNow = datetime.now() 
31
        batchId = int(time.mktime(datetimeNow.timetuple()))
45
        batchId = int(time.mktime(datetimeNow.timetuple()))
32
        if(refundToWallet(batchId, userCashbacksMap, 'App')):
46
        if(refundToWallet(batchId, userCashbacksMap)):
33
            for userCashback in userCashbacksToBeCredited:
47
            for userCashback in userCashbacksToBeCredited:
34
                userCashback.status = 'Credited'
48
                userCashback.status = 'Credited'
35
                userCashback.batchCreditId = batchId
49
                userCashback.batchCreditId = batchId
36
            session.commit()
50
            session.commit()
-
 
51
            
-
 
52
            for key, value in userCashbacksMap.iteritems():
-
 
53
                get_mongo_connection().Dtr.refund.insert({"userId": key, "batch":batchId, "userAmount":value, "timestamp":datetime.strftime(datetimeNow,"%Y-%m-%d %H:%M:%S"), "type":utils.CREDIT_TYPE_APP})
-
 
54
                get_mongo_connection().Dtr.user.update({"userId":key}, {"$inc": { "credited": value, utils.CREDIT_TYPE_APP:value}}, upsert=True)
37
        
55
        
38
def main(argv):
56
def main(argv):
39
    runtype = 'dry'
57
    runtype = 'dry'
40
    try:
58
    try:
41
        opts, args = getopt.getopt(argv,"ht:",["runtype="])
59
        opts, args = getopt.getopt(argv,"ht:",["runtype="])