| Line 123... |
Line 123... |
| 123 |
|
123 |
|
| 124 |
#This should be exposed from api for specific sources
|
124 |
#This should be exposed from api for specific sources
|
| 125 |
def scrapeStoreOrders(self):
|
125 |
def scrapeStoreOrders(self):
|
| 126 |
orders = self.db.merchantOrder.find({"storeId":1, "closed":False, "subOrders.closed":False, "subOrders.trackingUrl":{"$exists":True}})
|
126 |
orders = self.db.merchantOrder.find({"storeId":1, "closed":False, "subOrders.closed":False, "subOrders.trackingUrl":{"$exists":True}})
|
| 127 |
for merchantOrder in orders:
|
127 |
for merchantOrder in orders:
|
| - |
|
128 |
executeBulk = False
|
| 128 |
try:
|
129 |
try:
|
| 129 |
bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
|
130 |
bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
|
| 130 |
closed = True
|
131 |
closed = True
|
| 131 |
map1 = {}
|
132 |
map1 = {}
|
| 132 |
for subOrder in merchantOrder.get("subOrders"):
|
133 |
for subOrder in merchantOrder.get("subOrders"):
|
| 133 |
if subOrder.get("closed"):
|
134 |
if subOrder.get("closed"):
|
| 134 |
continue
|
135 |
continue
|
| 135 |
elif subOrder.get("trackingUrl") is None:
|
136 |
elif subOrder.get("trackingUrl") is None:
|
| 136 |
closed = False
|
137 |
closed = False
|
| 137 |
continue
|
138 |
continue
|
| - |
|
139 |
executeBulk = True
|
| 138 |
findMap = {"orderId":merchantOrder.get("orderId"), "subOrders.merchantSubOrderId":subOrder.get("merchantSubOrderId")}
|
140 |
findMap = {"orderId":merchantOrder.get("orderId"), "subOrders.merchantSubOrderId":subOrder.get("merchantSubOrderId")}
|
| 139 |
trackingUrl = subOrder.get("trackingUrl")
|
141 |
trackingUrl = subOrder.get("trackingUrl")
|
| 140 |
if not map1.has_key(trackingUrl):
|
142 |
if not map1.has_key(trackingUrl):
|
| 141 |
map1[trackingUrl] = self.parseTrackingUrl(trackingUrl)
|
143 |
map1[trackingUrl] = self.parseTrackingUrl(trackingUrl)
|
| 142 |
newOrder = map1.get(trackingUrl)
|
144 |
newOrder = map1.get(trackingUrl)
|
| 143 |
newOrder['cashBackStatus'] = subOrder.get('cashBackStatus')
|
145 |
newOrder['cashBackStatus'] = subOrder.get('cashBackStatus')
|
| 144 |
updateMap = self.getUpdateMap(newOrder)
|
146 |
updateMap = self.getUpdateMap(newOrder)
|
| 145 |
print findMap, "\n", updateMap
|
147 |
print findMap, "\n", updateMap
|
| 146 |
bulk.find(findMap).update({'$set' : updateMap})
|
148 |
bulk.find(findMap).update({'$set' : updateMap})
|
| 147 |
closed = closed and newOrder['closed']
|
149 |
closed = closed and newOrder['closed']
|
| - |
|
150 |
if executeBulk:
|
| 148 |
bulk.find({"orderId":merchantOrder.get("orderId")}).update({"$set":{"closed":closed, "parseError":False}})
|
151 |
bulk.find({"orderId":merchantOrder.get("orderId")}).update({"$set":{"closed":closed, "parseError":False}})
|
| 149 |
result = bulk.execute()
|
152 |
bulk.execute()
|
| 150 |
tprint(result)
|
- |
|
| 151 |
except:
|
153 |
except:
|
| 152 |
tprint("Could not update " + str(merchantOrder['orderId']) + " For store " + self.getName())
|
154 |
tprint("Could not update " + str(merchantOrder['orderId']) + " For store " + self.getName())
|
| 153 |
self.db.merchantOrder.update({"orderId":merchantOrder['orderId']}, {"$set":{"parseError":True}})
|
155 |
self.db.merchantOrder.update({"orderId":merchantOrder['orderId']}, {"$set":{"parseError":True}})
|
| 154 |
traceback.print_exc()
|
156 |
traceback.print_exc()
|
| 155 |
|
157 |
|
| Line 545... |
Line 547... |
| 545 |
|
547 |
|
| 546 |
|
548 |
|
| 547 |
|
549 |
|
| 548 |
|
550 |
|
| 549 |
def main():
|
551 |
def main():
|
| 550 |
#readSSh("/tmp/User229/171-8846602-5720325")
|
552 |
#readSSh("orderSummary24-04:22:22:15")
|
| 551 |
#readSSh("/tmp/User229/403-3423933-9264353")
|
553 |
readSSh("/tmp/User157/orderSummary24-04:01:15:36")
|
| 552 |
|
554 |
|
| 553 |
store = getStore(1)
|
555 |
#store = getStore(1)
|
| 554 |
#store.scrapeStoreOrders()
|
556 |
#store.scrapeStoreOrders()
|
| 555 |
# br = mechanize.Browser()
|
557 |
# br = mechanize.Browser()
|
| 556 |
# br.addheaders = [('User-agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'),
|
558 |
# br.addheaders = [('User-agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'),
|
| 557 |
# ('Accept', 'text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8'),
|
559 |
# ('Accept', 'text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8'),
|
| 558 |
# ('Accept-Encoding', 'gzip,deflate,sdch'),
|
560 |
# ('Accept-Encoding', 'gzip,deflate,sdch'),
|
| 559 |
# ('Accept-Language', 'en-US,en;q=0.8'),
|
561 |
# ('Accept-Language', 'en-US,en;q=0.8'),
|
| 560 |
# ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
|
562 |
# ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
|
| 561 |
# store.scrapeStoreOrders()
|
563 |
# store.scrapeStoreOrders()
|
| 562 |
#store.parseOrderRawHtml(1306, "13232", 14, readSSh("/home/amit/2158.html"), "https://www.amazon.in/gp/buy/spc/handlers/static-submit-decoupled.html/ref=ox_spc_place_order?ie=UTF8&fromAnywhere=1&hasWorkingJav")
|
564 |
#store.parseOrderRawHtml(1306, "13232", 14, readSSh("/home/amit/2158.html"), "https://www.amazon.in/gp/buy/spc/handlers/static-submit-decoupled.html/ref=ox_spc_place_order?ie=UTF8&fromAnywhere=1&hasWorkingJav")
|
| 563 |
store.trackOrdersForUser(94, "https://www.amazon.in/gp/css/order-history", readSSh("/tmp/User94/orderSummary24-04:08:07:34"))
|
565 |
#store.trackOrdersForUser(94, "https://www.amazon.in/gp/css/order-history", readSSh("/tmp/User94/orderSummary24-04:08:07:34"))
|
| 564 |
#readSSh("/tmp/User211/2015-04-12 10:32:41.905765")
|
566 |
#readSSh("/tmp/User211/2015-04-12 10:32:41.905765")
|
| 565 |
#store.scrapeAffiliate()
|
567 |
#store.scrapeAffiliate()
|
| 566 |
def readSSh(fileName):
|
568 |
def readSSh(fileName):
|
| 567 |
try:
|
569 |
try:
|
| 568 |
str1 = open(fileName).read()
|
570 |
str1 = open(fileName).read()
|