Subversion Repositories SmartDukaan

Rev

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

Rev 13631 Rev 13662
Line 3... Line 3...
3
 
3
 
4
@author: amit
4
@author: amit
5
'''
5
'''
6
from pymongo.mongo_client import MongoClient
6
from pymongo.mongo_client import MongoClient
7
import importlib
7
import importlib
-
 
8
import json
-
 
9
import math
8
import mechanize
10
import mechanize
9
import traceback
11
import traceback
-
 
12
import urllib
-
 
13
import urllib2
10
sourceMap = {1:"amazon", 2:"flipkart", 3:"snapdeal", 4:"spice", 5:"homeshop18"}
14
sourceMap = {1:"amazon", 2:"flipkart", 3:"snapdeal", 4:"spice", 5:"homeshop18"}
-
 
15
headers = { 
-
 
16
           'User-agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
-
 
17
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
-
 
18
            'Accept-Language' : 'en-US,en;q=0.8',                     
-
 
19
            'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
11
 
20
        }
-
 
21
CASHBACK_URL = 'http://api.profittill.com/cashbacks/index/%s/%s'
12
 
22
 
13
def getStore(source_id):
23
def getStore(source_id):
14
    #module = sourceMap[source_id]
24
    #module = sourceMap[source_id]
15
    store = Store(source_id)
25
    store = Store(source_id)
16
    try:
26
    try:
Line 50... Line 60...
50
    ORDER_PLACED = 'Order Placed'
60
    ORDER_PLACED = 'Order Placed'
51
    ORDER_DELIVERED = 'Delivered'
61
    ORDER_DELIVERED = 'Delivered'
52
    ORDER_SHIPPED = 'Shipped' #Lets see if we can make use of it
62
    ORDER_SHIPPED = 'Shipped' #Lets see if we can make use of it
53
    ORDER_CANCELLED = 'Cancelled'
63
    ORDER_CANCELLED = 'Cancelled'
54
    
64
    
-
 
65
    CB_INIT = 'Waiting Confirmation'
55
    CB_PENDING = 'Pending'
66
    CB_PENDING = 'Pending'
56
    CB_CREDITED = 'Credited to wallet'
67
    CB_CREDITED = 'Credited to wallet'
57
    CB_NA = 'Not Applicable'
68
    CB_NA = 'Not Applicable'
58
    CB_APPROVED = 'Approved'
69
    CB_APPROVED = 'Approved'
59
    CB_CANCELLED = 'Cancelled'
70
    CB_CANCELLED = 'Cancelled'
60
    
71
    
-
 
72
    CONF_CB_SELLING_PRICE = 0
-
 
73
    CONF_CB_DISCOUNTED_PRICE = 1
61
    
74
    
62
    def __init__(self, store_id):
75
    def __init__(self, store_id):
-
 
76
        client = MongoClient('mongodb://localhost:27017/')
-
 
77
        self.db = client.Dtr
63
        self.store_id = store_id
78
        self.store_id = store_id
64
        self.store_name = sourceMap[store_id]
79
        self.store_name = sourceMap[store_id]
65
    
80
    
-
 
81
    '''
-
 
82
    To Settle payback for respective stores.
-
 
83
    Also ensures that settlement happens only for approved orders
-
 
84
    '''
-
 
85
    def settlePayBack(self):
-
 
86
        orders = self.db.merchantOrder.find({'subOrders.cashBackStatus':Store.CB_APPROVED}, {'userId':1, 'subOrders.cashBackAmount':1})
-
 
87
        #for 
-
 
88
        
-
 
89
            
66
    
90
    
67
    def getName(self):
91
    def getName(self):
68
        raise NotImplementedError
92
        raise NotImplementedError
69
    
93
    
70
    def scrapeAffiliate(self, startDate=None, endDate=None):
94
    def scrapeAffiliate(self, startDate=None, endDate=None):
Line 74... Line 98...
74
        raise NotImplementedError
98
        raise NotImplementedError
75
    
99
    
76
    def scrapeStoreOrders(self,):
100
    def scrapeStoreOrders(self,):
77
        raise NotImplementedError
101
        raise NotImplementedError
78
    
102
    
79
    '''
103
    
80
    To Settle payback for respective stores.
104
    def getCashbackAmount(self, productCode, amount):
-
 
105
        alagvar = CASHBACK_URL % (self.store_id,productCode)
-
 
106
        print alagvar
81
    Also ensures that settlement happens only for closed orders
107
        filehandle = urllib2.Request(alagvar,headers=headers)
-
 
108
        x= urllib2.urlopen(filehandle)
-
 
109
        map = json.loads(x.read())
-
 
110
        if map['cashback']==0:
-
 
111
            return 0
82
    '''
112
        else:
-
 
113
            if map['cashback_type'] == 'percentage':
-
 
114
                return math.floor((amount * map['cashback'])/100)
83
    def settlePayBack(self,):
115
            else:
84
        raise NotImplemented
116
                return map['cashback']
-
 
117
    
85
    '''
118
    '''
86
    Parses the order for specific store
119
    Parses the order for specific store
87
    
120
    
88
    order id, total amount, created on(now() if could not parse
121
    order id, total amount, created on(now() if could not parse
89
    suborder id, title, quantity, unit price, expected delivery date,
122
    suborder id, title, quantity, unit price, expected delivery date,
Line 100... Line 133...
100
    '''
133
    '''
101
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
134
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
102
        
135
        
103
        pass
136
        pass
104
    
137
    
105
if __name__ == '__main__':
138
def main():
106
    store = getStore(3)
139
    store = getStore(3)
-
 
140
    print store.getCashbackAmount('864683341', 100)
-
 
141
        
107
    store.scrapeAffiliate()
142
if __name__ == '__main__':
-
 
143
    main()
108
 
144
 
109
 
145
 
110
def getBrowserObject():
146
def getBrowserObject():
111
    import cookielib
147
    import cookielib
112
    br = mechanize.Browser(factory=mechanize.RobustFactory())
148
    br = mechanize.Browser(factory=mechanize.RobustFactory())