| Line 139... |
Line 139... |
| 139 |
except:
|
139 |
except:
|
| 140 |
tprint("Could not update " + str(order['orderId']))
|
140 |
tprint("Could not update " + str(order['orderId']))
|
| 141 |
traceback.print_exc()
|
141 |
traceback.print_exc()
|
| 142 |
def scrapeAffiliate(self, startDate=None, endDate=None):
|
142 |
def scrapeAffiliate(self, startDate=None, endDate=None):
|
| 143 |
#get all yesterday's affiliate in pending or cancelled state and update to system
|
143 |
#get all yesterday's affiliate in pending or cancelled state and update to system
|
| 144 |
if datetime.now().hour == 6:
|
- |
|
| 145 |
offers = []
|
144 |
offers = []
|
| 146 |
br = getBrowserObject()
|
145 |
br = getBrowserObject()
|
| 147 |
br.open(AFFILIATE_URL)
|
146 |
br.open(AFFILIATE_URL)
|
| 148 |
response = br.response() # copy
|
147 |
response = br.response() # copy
|
| 149 |
token = re.findall('window.__FK = "(.*?)"', ungzipResponse(response), re.IGNORECASE)[0]
|
148 |
token = re.findall('window.__FK = "(.*?)"', ungzipResponse(response), re.IGNORECASE)[0]
|
| 150 |
data = {'__FK':token,
|
149 |
data = {'__FK':token,
|
| 151 |
'email':'saholic1@gmail.com',
|
150 |
'email':'saholic1@gmail.com',
|
| 152 |
'password':'e8aacf6fc1e3998186a4a8e56e428f66'
|
151 |
'password':'e8aacf6fc1e3998186a4a8e56e428f66'
|
| 153 |
}
|
152 |
}
|
| 154 |
br.open(AFFILIATE_LOGIN_URL, urllib.urlencode(data))
|
153 |
br.open(AFFILIATE_LOGIN_URL, urllib.urlencode(data))
|
| 155 |
for delta in range(1,45):
|
154 |
for delta in range(1,45):
|
| 156 |
yester5date = date.today() - timedelta(delta)
|
155 |
yester5date = date.today() - timedelta(delta)
|
| 157 |
syester5date = yester5date.strftime('%Y-%m-%d')
|
156 |
syester5date = yester5date.strftime('%Y-%m-%d')
|
| 158 |
for status in [AFF_STATUS_PENDING, AFF_STATUS_CANCELLED, AFF_STATUS_DISAPPROVED]:
|
157 |
for status in [AFF_STATUS_PENDING, AFF_STATUS_CANCELLED, AFF_STATUS_DISAPPROVED]:
|
| 159 |
try:
|
158 |
try:
|
| 160 |
br.open(AFF_REPORT_URL % (status, syester5date, syester5date))
|
159 |
br.open(AFF_REPORT_URL % (status, syester5date, syester5date))
|
| 161 |
except:
|
160 |
except:
|
| 162 |
tprint("Could not fetch data for Status %s and date %s"%(status, syester5date))
|
161 |
tprint("Could not fetch data for Status %s and date %s"%(status, syester5date))
|
| 163 |
page = ungzipResponse(br.response())
|
162 |
page = ungzipResponse(br.response())
|
| 164 |
soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
|
163 |
soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
|
| 165 |
soup.table
|
164 |
soup.table
|
| 166 |
try:
|
165 |
try:
|
| 167 |
tableElement = soup.findAll('table', {'class':'report-table fixtable'})[1]
|
166 |
tableElement = soup.findAll('table', {'class':'report-table fixtable'})[1]
|
| 168 |
except:
|
167 |
except:
|
| 169 |
continue
|
168 |
continue
|
| 170 |
trElements = tableElement.findAll('tr')
|
169 |
trElements = tableElement.findAll('tr')
|
| 171 |
trElements.pop(0)
|
170 |
trElements.pop(0)
|
| 172 |
for trElement in trElements:
|
171 |
for trElement in trElements:
|
| 173 |
tdElements = trElement.findAll('td')
|
172 |
tdElements = trElement.findAll('td')
|
| 174 |
productCode = re.findall(r'pid=(.*)$', tdElements[0].find('a')['href'])[0]
|
173 |
productCode = re.findall(r'pid=(.*)$', tdElements[0].find('a')['href'])[0]
|
| 175 |
quantity =int(tdElements[3].text)
|
174 |
quantity =int(tdElements[3].text)
|
| 176 |
price = int(float(tdElements[2].text.strip().replace(",","")))
|
175 |
price = int(float(tdElements[2].text.strip().replace(",","")))
|
| 177 |
payOut = int(float(tdElements[6].text.strip().replace(",","")))
|
176 |
payOut = int(float(tdElements[6].text.strip().replace(",","")))
|
| 178 |
saleAmount = int(float(tdElements[4].text.strip().replace(",","")))
|
177 |
saleAmount = int(float(tdElements[4].text.strip().replace(",","")))
|
| 179 |
subTagId = tdElements[7].text.strip()
|
178 |
subTagId = tdElements[7].text.strip()
|
| 180 |
category = tdElements[1].text.strip()
|
179 |
category = tdElements[1].text.strip()
|
| 181 |
affiliateInfo = FlipkartAffiliateInfo(subTagId, syester5date, productCode, price, quantity, saleAmount, payOut, status, category)
|
180 |
affiliateInfo = FlipkartAffiliateInfo(subTagId, syester5date, productCode, price, quantity, saleAmount, payOut, status, category)
|
| 182 |
#updateMap['subOrders.$.unitPrice'] = price
|
181 |
#updateMap['subOrders.$.unitPrice'] = price
|
| 183 |
#updateMap['subOrders.$.cashBackAmount'], updateMap['subOrders.$.cashBacPercentage'] = self.getCashbackAmount(productCode, price)
|
182 |
#updateMap['subOrders.$.cashBackAmount'], updateMap['subOrders.$.cashBacPercentage'] = self.getCashbackAmount(productCode, price)
|
| 184 |
offers.append(affiliateInfo)
|
183 |
offers.append(affiliateInfo)
|
| 185 |
self._saveToAffiliate(offers)
|
184 |
self._saveToAffiliate(offers)
|
| 186 |
|
185 |
|
| 187 |
def _saveToAffiliate(self, offers):
|
186 |
def _saveToAffiliate(self, offers):
|
| 188 |
collection = self.db.flipkartOrderAffiliateInfo
|
187 |
collection = self.db.flipkartOrderAffiliateInfo
|
| 189 |
mcollection = self.db.merchantOrder
|
188 |
mcollection = self.db.merchantOrder
|
| 190 |
for offer in offers:
|
189 |
for offer in offers:
|