| Line 9... |
Line 9... |
| 9 |
from dtr.dao import AffiliateInfo, Order, SubOrder, FlipkartAffiliateInfo
|
9 |
from dtr.dao import AffiliateInfo, Order, SubOrder, FlipkartAffiliateInfo
|
| 10 |
from dtr.main import getBrowserObject, getStore, ParseException, ungzipResponse, \
|
10 |
from dtr.main import getBrowserObject, getStore, ParseException, ungzipResponse, \
|
| 11 |
Store as MStore, sourceMap, tprint
|
11 |
Store as MStore, sourceMap, tprint
|
| 12 |
from dtr.reports.affiliatereco import getSkuData
|
12 |
from dtr.reports.affiliatereco import getSkuData
|
| 13 |
from dtr.storage.DataService import Clicks, Users, FlipkartOrders
|
13 |
from dtr.storage.DataService import Clicks, Users, FlipkartOrders
|
| - |
|
14 |
from dtr.utils import utils
|
| 14 |
from dtr.utils.utils import fetchResponseUsingProxy
|
15 |
from dtr.utils.utils import fetchResponseUsingProxy
|
| 15 |
from elixir import *
|
16 |
from elixir import *
|
| 16 |
from pprint import pprint
|
17 |
from pprint import pprint
|
| 17 |
from pymongo.mongo_client import MongoClient
|
18 |
from pymongo.mongo_client import MongoClient
|
| 18 |
import hashlib
|
19 |
import hashlib
|
| Line 32... |
Line 33... |
| 32 |
AFF_REPORT_URL='http://www.flipkart.com/affiliate/reports/ordersReport?order_status_filter=%s&startdate=%s&enddate=%s&page=%s'
|
33 |
AFF_REPORT_URL='http://www.flipkart.com/affiliate/reports/ordersReport?order_status_filter=%s&startdate=%s&enddate=%s&page=%s'
|
| 33 |
AFF_STATUS_CANCELLED='cancelled'
|
34 |
AFF_STATUS_CANCELLED='cancelled'
|
| 34 |
AFF_STATUS_APPROVED='approved'
|
35 |
AFF_STATUS_APPROVED='approved'
|
| 35 |
AFF_STATUS_DISAPPROVED='disapproved'
|
36 |
AFF_STATUS_DISAPPROVED='disapproved'
|
| 36 |
AFF_STATUS_PENDING='pending'
|
37 |
AFF_STATUS_PENDING='pending'
|
| - |
|
38 |
statuses = [AFF_STATUS_CANCELLED,AFF_STATUS_APPROVED,AFF_STATUS_DISAPPROVED,AFF_STATUS_PENDING ]
|
| 37 |
categoryMap = {3:"Mobiles", 5:"Tablets"}
|
39 |
categoryMap = {3:"Mobiles", 5:"Tablets"}
|
| 38 |
|
40 |
|
| 39 |
|
41 |
|
| 40 |
class Store(MStore):
|
42 |
class Store(MStore):
|
| 41 |
OrderStatusMap = {
|
43 |
OrderStatusMap = {
|
| Line 162... |
Line 164... |
| 162 |
}
|
164 |
}
|
| 163 |
br.open(AFFILIATE_LOGIN_URL, urllib.urlencode(data))
|
165 |
br.open(AFFILIATE_LOGIN_URL, urllib.urlencode(data))
|
| 164 |
for delta in range(1,2):
|
166 |
for delta in range(1,2):
|
| 165 |
yester5date = date.today() - timedelta(delta)
|
167 |
yester5date = date.today() - timedelta(delta)
|
| 166 |
syester5date = yester5date.strftime('%Y-%m-%d')
|
168 |
syester5date = yester5date.strftime('%Y-%m-%d')
|
| 167 |
for status in [AFF_STATUS_PENDING, AFF_STATUS_CANCELLED, AFF_STATUS_DISAPPROVED]:
|
169 |
for status in [AFF_STATUS_PENDING, AFF_STATUS_CANCELLED, AFF_STATUS_DISAPPROVED,AFF_STATUS_APPROVED]:
|
| 168 |
hasPagination=True
|
170 |
hasPagination=True
|
| 169 |
pagination = 0
|
171 |
pagination = 0
|
| 170 |
while hasPagination:
|
172 |
while hasPagination:
|
| 171 |
pagination = pagination + 1
|
173 |
pagination = pagination + 1
|
| 172 |
print "pagination", pagination
|
- |
|
| 173 |
try:
|
174 |
try:
|
| 174 |
br.open(AFF_REPORT_URL % (status, syester5date, syester5date, pagination))
|
175 |
br.open(AFF_REPORT_URL % (status, syester5date, syester5date, pagination))
|
| 175 |
except:
|
176 |
except:
|
| 176 |
tprint("Could not fetch data for Status %s and date %s"%(status, syester5date))
|
177 |
tprint("Could not fetch data for Status %s and date %s and pagination %s"%(status, syester5date, pagination))
|
| 177 |
page = ungzipResponse(br.response())
|
178 |
page = ungzipResponse(br.response())
|
| 178 |
soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
|
179 |
soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
|
| 179 |
soup.table
|
180 |
soup.table
|
| 180 |
try:
|
181 |
try:
|
| 181 |
tableElement = soup.findAll('table', {'class':'report-table fixtable'})[1]
|
182 |
tableElement = soup.findAll('table', {'class':'report-table fixtable'})[1]
|
| Line 199... |
Line 200... |
| 199 |
affiliateInfo = FlipkartAffiliateInfo(subTagId, syester5date, productCode, price, quantity, saleAmount, payOut, status, category)
|
200 |
affiliateInfo = FlipkartAffiliateInfo(subTagId, syester5date, productCode, price, quantity, saleAmount, payOut, status, category)
|
| 200 |
affiliateInfo.productTitle = tdElements[0].find('a').text
|
201 |
affiliateInfo.productTitle = tdElements[0].find('a').text
|
| 201 |
#updateMap['subOrders.$.unitPrice'] = price
|
202 |
#updateMap['subOrders.$.unitPrice'] = price
|
| 202 |
#updateMap['subOrders.$.cashBackAmount'], updateMap['subOrders.$.cashBacPercentage'] = self.getCashbackAmount(productCode, price)
|
203 |
#updateMap['subOrders.$.cashBackAmount'], updateMap['subOrders.$.cashBacPercentage'] = self.getCashbackAmount(productCode, price)
|
| 203 |
offers.append(affiliateInfo)
|
204 |
offers.append(affiliateInfo)
|
| - |
|
205 |
tprint("Successfully updated fetch data for Status %s and date %s and pagination %s"%(status, syester5date, pagination))
|
| 204 |
self._saveToAffiliate(offers)
|
206 |
self._saveToAffiliate(offers)
|
| 205 |
|
207 |
|
| 206 |
yester5date = date.today() - timedelta(1)
|
208 |
yester5date = date.today() - timedelta(1)
|
| 207 |
syester5date = yester5date.strftime('%Y-%m-%d')
|
209 |
syester5date = yester5date.strftime('%Y-%m-%d')
|
| 208 |
self.db.flipkartOrderAffiliateInfo.find({"saleDate":syester5date})
|
210 |
self.db.flipkartOrderAffiliateInfo.find({"saleDate":syester5date})
|
| Line 441... |
Line 443... |
| 441 |
def hex_md5(password):
|
443 |
def hex_md5(password):
|
| 442 |
m = hashlib.md5()
|
444 |
m = hashlib.md5()
|
| 443 |
print(m.digest())
|
445 |
print(m.digest())
|
| 444 |
|
446 |
|
| 445 |
def main():
|
447 |
def main():
|
| - |
|
448 |
requestDownload()
|
| - |
|
449 |
|
| - |
|
450 |
|
| 446 |
|
451 |
|
| - |
|
452 |
|
| 447 |
store = getStore(2)
|
453 |
#store = getStore(2)
|
| 448 |
store.scrapeAffiliate()
|
454 |
#store.scrapeAffiliate()
|
| 449 |
#store.scrapeStoreOrders()
|
455 |
#store.scrapeStoreOrders()
|
| 450 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3016502908102575&token=0db4c692bacbfbfc158b52358ac9e91e&src=or&pr=1')
|
456 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3016502908102575&token=0db4c692bacbfbfc158b52358ac9e91e&src=or&pr=1')
|
| 451 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3018701137253850&token=f7402ddcf2b63b37cc6bc528cc115d2f&src=or&pr=1')
|
457 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3018701137253850&token=f7402ddcf2b63b37cc6bc528cc115d2f&src=or&pr=1')
|
| 452 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
458 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
| 453 |
#store.flipkartOrderTracking(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
459 |
#store.flipkartOrderTracking(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
| Line 455... |
Line 461... |
| 455 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://dl.flipkart.com/orderresponse?reference_id=OD1019453634552336&token=e8e04871ad65b532aa53fa82bb34b901&src=or&pr=1')
|
461 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://dl.flipkart.com/orderresponse?reference_id=OD1019453634552336&token=e8e04871ad65b532aa53fa82bb34b901&src=or&pr=1')
|
| 456 |
#hex_md5('spice@2020')
|
462 |
#hex_md5('spice@2020')
|
| 457 |
#store.getCashbackAmount('MOBDVHC6XKKPZ3GZ', 5999)
|
463 |
#store.getCashbackAmount('MOBDVHC6XKKPZ3GZ', 5999)
|
| 458 |
|
464 |
|
| 459 |
|
465 |
|
| 460 |
if __name__ == '__main__':
|
- |
|
| 461 |
main()
|
- |
|
| 462 |
|
466 |
|
| 463 |
|
467 |
|
| - |
|
468 |
def requestDownload():
|
| - |
|
469 |
requestReportUrl = "http://www.flipkart.com/affiliate/download/request"
|
| - |
|
470 |
br = getBrowserObject()
|
| - |
|
471 |
br.set_debug_responses(True)
|
| - |
|
472 |
br.open(AFFILIATE_URL)
|
| - |
|
473 |
response = br.response() # copy
|
| - |
|
474 |
token = re.findall('window.__FK = "(.*?)"', utils.ungzipResponse(response), re.IGNORECASE)[0]
|
| - |
|
475 |
data = {'__FK':token,
|
| - |
|
476 |
'email':'saholic1@gmail.com',
|
| - |
|
477 |
'password':'e8aacf6fc1e3998186a4a8e56e428f66'
|
| - |
|
478 |
}
|
| - |
|
479 |
br.open(AFFILIATE_LOGIN_URL, urllib.urlencode(data))
|
| - |
|
480 |
till = date.today()
|
| - |
|
481 |
start = date.today() - timedelta(2)
|
| - |
|
482 |
target = open("dowloadreportids", 'w')
|
| - |
|
483 |
target.truncate()
|
| - |
|
484 |
for status in statuses:
|
| - |
|
485 |
data = getRequestDownloadData(token, start, till, status)
|
| - |
|
486 |
response = utils.ungzipResponse(br.open(requestReportUrl, urllib.urlencode(data)))
|
| - |
|
487 |
target.write(response)
|
| - |
|
488 |
|
| - |
|
489 |
target.close()
|
| - |
|
490 |
|
| - |
|
491 |
|
| - |
|
492 |
def getRequestDownloadData(token, start, till, status):
|
| - |
|
493 |
return (
|
| - |
|
494 |
('__FK',token),
|
| - |
|
495 |
('parameters[from]', start),
|
| - |
|
496 |
('parameters[till]', till),
|
| - |
|
497 |
('parameters[filter]', status),
|
| - |
|
498 |
('type','OrdersReport'),
|
| - |
|
499 |
)
|
| 464 |
|
500 |
|
| 465 |
|
501 |
|
| 466 |
def todict(obj, classkey=None):
|
502 |
def todict(obj, classkey=None):
|
| 467 |
if isinstance(obj, dict):
|
503 |
if isinstance(obj, dict):
|
| 468 |
data = {}
|
504 |
data = {}
|
| Line 481... |
Line 517... |
| 481 |
data[classkey] = obj.__class__.__name__
|
517 |
data[classkey] = obj.__class__.__name__
|
| 482 |
return data
|
518 |
return data
|
| 483 |
else:
|
519 |
else:
|
| 484 |
return obj
|
520 |
return obj
|
| 485 |
|
521 |
|
| - |
|
522 |
if __name__ == '__main__':
|
| - |
|
523 |
main()
|
| 486 |
|
524 |
|
| 487 |
|
525 |
|