| 14450 |
amit.gupta |
1 |
'''
|
|
|
2 |
Created on Mar 13, 2015
|
|
|
3 |
|
|
|
4 |
@author: amit
|
|
|
5 |
'''
|
|
|
6 |
from datetime import date, datetime, timedelta
|
| 14632 |
amit.gupta |
7 |
from dtr.main import Store, sourceMap
|
| 14650 |
amit.gupta |
8 |
from dtr.reports.amazonreco import generateAmazonReco
|
| 14613 |
amit.gupta |
9 |
from dtr.storage import Mysql
|
|
|
10 |
from dtr.storage.Mysql import getOrdersAfterDate, getOrdersByTag
|
| 14450 |
amit.gupta |
11 |
from email import encoders
|
|
|
12 |
from email.mime.base import MIMEBase
|
|
|
13 |
from email.mime.multipart import MIMEMultipart
|
|
|
14 |
from email.mime.text import MIMEText
|
|
|
15 |
from pymongo.mongo_client import MongoClient
|
| 14460 |
amit.gupta |
16 |
from xlrd import open_workbook
|
| 14524 |
amit.gupta |
17 |
from xlutils.copy import copy
|
| 14460 |
amit.gupta |
18 |
from xlwt.Workbook import Workbook
|
| 14450 |
amit.gupta |
19 |
import MySQLdb
|
|
|
20 |
import smtplib
|
|
|
21 |
import time
|
|
|
22 |
import xlwt
|
| 14460 |
amit.gupta |
23 |
#from xlwt import
|
| 14450 |
amit.gupta |
24 |
|
|
|
25 |
client = MongoClient('mongodb://localhost:27017/')
|
|
|
26 |
|
|
|
27 |
SENDER = "cnc.center@shop2020.in"
|
|
|
28 |
PASSWORD = "5h0p2o2o"
|
|
|
29 |
SUBJECT = "DTR User Segmentation report for " + date.today().isoformat()
|
|
|
30 |
SMTP_SERVER = "smtp.gmail.com"
|
|
|
31 |
SMTP_PORT = 587
|
|
|
32 |
|
| 14647 |
amit.gupta |
33 |
XLS_FILENAME = "snapdealaffiliatereco.xls"
|
| 14632 |
amit.gupta |
34 |
XLS_O_FILENAME = "allorders.xls"
|
| 14647 |
amit.gupta |
35 |
XLS_F_FILENAME = "flipkartaffiliatereco.xls"
|
| 14650 |
amit.gupta |
36 |
XLS_A_FILENAME = "amazonaffiliatereco.xls"
|
| 14460 |
amit.gupta |
37 |
boldStyle = xlwt.XFStyle()
|
|
|
38 |
f = xlwt.Font()
|
|
|
39 |
f.bold = True
|
|
|
40 |
boldStyle.font = f
|
|
|
41 |
i = -1
|
| 14616 |
amit.gupta |
42 |
|
|
|
43 |
datetime_format = xlwt.XFStyle()
|
|
|
44 |
datetime_format.num_format_str = 'dd/mm/yyyy HH:MM AM/PM'
|
|
|
45 |
|
| 14450 |
amit.gupta |
46 |
def generateFlipkartReco():
|
| 14508 |
amit.gupta |
47 |
global i
|
|
|
48 |
i = -1
|
| 14460 |
amit.gupta |
49 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 2)
|
|
|
50 |
db = client.Dtr
|
| 14647 |
amit.gupta |
51 |
wb = xlwt.Workbook()
|
|
|
52 |
#rb = open_workbook(XLS_F_FILENAME)
|
|
|
53 |
#wb = copy(rb)
|
| 14460 |
amit.gupta |
54 |
#wb = xlwt.Workbook()
|
|
|
55 |
row = 0
|
| 14647 |
amit.gupta |
56 |
row2 = 0
|
|
|
57 |
row3 = 0
|
|
|
58 |
row4 = 0
|
|
|
59 |
worksheet = wb.add_sheet("All Orders")
|
|
|
60 |
worksheet1 = wb.add_sheet("Orders Reconciled")
|
|
|
61 |
worksheet2 = wb.add_sheet("Orders not Reconciled")
|
|
|
62 |
worksheet3 = wb.add_sheet("Aff not Reconciled")
|
| 14460 |
amit.gupta |
63 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
| 14647 |
amit.gupta |
64 |
worksheet1.write(row, i, 'Order Id', boldStyle)
|
|
|
65 |
worksheet2.write(row, i, 'Order Id', boldStyle)
|
| 14460 |
amit.gupta |
66 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
| 14647 |
amit.gupta |
67 |
worksheet1.write(row, i, 'User Id', boldStyle)
|
|
|
68 |
worksheet2.write(row, i, 'User Id', boldStyle)
|
| 14474 |
amit.gupta |
69 |
worksheet.write(row, inc(), 'Username', boldStyle)
|
| 14647 |
amit.gupta |
70 |
worksheet1.write(row, i, 'Username', boldStyle)
|
|
|
71 |
worksheet2.write(row, i, 'Username', boldStyle)
|
| 14771 |
amit.gupta |
72 |
worksheet.write(row, inc(), 'Version code', boldStyle)
|
|
|
73 |
worksheet1.write(row, i, 'Version code', boldStyle)
|
|
|
74 |
worksheet2.write(row, i, 'Version code', boldStyle)
|
|
|
75 |
worksheet.write(row, inc(), 'Device', boldStyle)
|
|
|
76 |
worksheet1.write(row, i, 'Device', boldStyle)
|
|
|
77 |
worksheet2.write(row, i, 'Device', boldStyle)
|
| 14460 |
amit.gupta |
78 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
| 14647 |
amit.gupta |
79 |
worksheet1.write(row, i, 'Merchant Order Id', boldStyle)
|
|
|
80 |
worksheet2.write(row, i, 'Merchant Order Id', boldStyle)
|
| 14460 |
amit.gupta |
81 |
worksheet.write(row, inc(), 'Product Title', boldStyle)
|
| 14647 |
amit.gupta |
82 |
worksheet1.write(row, i, 'Product Title', boldStyle)
|
|
|
83 |
worksheet2.write(row, i, 'Product Title', boldStyle)
|
| 14460 |
amit.gupta |
84 |
worksheet.write(row, inc(), 'Price', boldStyle)
|
| 14647 |
amit.gupta |
85 |
worksheet1.write(row, i, 'Price', boldStyle)
|
|
|
86 |
worksheet2.write(row, i, 'Price', boldStyle)
|
| 14460 |
amit.gupta |
87 |
worksheet.write(row, inc(), 'Quantity', boldStyle)
|
| 14647 |
amit.gupta |
88 |
worksheet1.write(row, i, 'Quantity', boldStyle)
|
|
|
89 |
worksheet2.write(row, i, 'Quantity', boldStyle)
|
| 14460 |
amit.gupta |
90 |
worksheet.write(row, inc(), 'Status', boldStyle)
|
| 14647 |
amit.gupta |
91 |
worksheet1.write(row, i, 'Status', boldStyle)
|
|
|
92 |
worksheet2.write(row, i, 'Status', boldStyle)
|
| 14460 |
amit.gupta |
93 |
worksheet.write(row, inc(), 'Detailed Status', boldStyle)
|
| 14647 |
amit.gupta |
94 |
worksheet1.write(row, i, 'Detailed Status', boldStyle)
|
|
|
95 |
worksheet2.write(row, i, 'Detailed Status', boldStyle)
|
| 14460 |
amit.gupta |
96 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
| 14647 |
amit.gupta |
97 |
worksheet1.write(row, i, 'Cashback Status', boldStyle)
|
|
|
98 |
worksheet2.write(row, i, 'Cashback Status', boldStyle)
|
| 14460 |
amit.gupta |
99 |
worksheet.write(row, inc(), 'Our CashBack', boldStyle)
|
| 14647 |
amit.gupta |
100 |
worksheet1.write(row, i, 'Our CashBack', boldStyle)
|
|
|
101 |
worksheet2.write(row, i, 'Our CashBack', boldStyle)
|
|
|
102 |
worksheet.write(row, inc(), 'Sale Date', boldStyle)
|
|
|
103 |
worksheet1.write(row, i, 'Sale Date', boldStyle)
|
|
|
104 |
worksheet2.write(row, i, 'Sale Date', boldStyle)
|
| 14460 |
amit.gupta |
105 |
worksheet.write(row, inc(), 'SubtagId', boldStyle)
|
| 14647 |
amit.gupta |
106 |
worksheet1.write(row, i, 'SubtagId', boldStyle)
|
|
|
107 |
worksheet2.write(row, i, 'SubtagId', boldStyle)
|
| 14460 |
amit.gupta |
108 |
worksheet.write(row, inc(), 'Category', boldStyle)
|
| 14647 |
amit.gupta |
109 |
worksheet1.write(row, i, 'Category', boldStyle)
|
| 14460 |
amit.gupta |
110 |
worksheet.write(row, inc(), 'Aff PayOut', boldStyle)
|
| 14647 |
amit.gupta |
111 |
worksheet1.write(row, i, 'Aff PayOut', boldStyle)
|
| 14460 |
amit.gupta |
112 |
worksheet.write(row, inc(), 'Aff Sale Amount', boldStyle)
|
| 14647 |
amit.gupta |
113 |
worksheet1.write(row, i, 'Aff Sale Amount', boldStyle)
|
| 14460 |
amit.gupta |
114 |
worksheet.write(row, inc(), 'Aff Sale Date', boldStyle)
|
| 14647 |
amit.gupta |
115 |
worksheet1.write(row, i, 'Aff Sale Date', boldStyle)
|
| 14460 |
amit.gupta |
116 |
for row1 in curs:
|
|
|
117 |
orderId = row1[0]
|
|
|
118 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
119 |
if order is None:
|
|
|
120 |
continue
|
|
|
121 |
saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%d %B, %Y %I:%M %p").replace(hour=0, minute=0, second=0, microsecond=0).timetuple()))
|
|
|
122 |
#saleTime1 = int(time.mktime((datetime.strptime(order['placedOn'], "%b %d, %Y %I:%M %p") + timedelta(seconds=-60)).timetuple()))
|
| 14647 |
amit.gupta |
123 |
reconciled_affiliates = []
|
| 14460 |
amit.gupta |
124 |
for subOrder in order['subOrders']:
|
| 14647 |
amit.gupta |
125 |
affs = list(db.flipkartOrderAffiliateInfo.find({"productCode":subOrder.get("productCode"), "saleDateInt":saleTime}))
|
| 14460 |
amit.gupta |
126 |
row += 1
|
|
|
127 |
i=-1
|
|
|
128 |
worksheet.write(row, inc(), orderId)
|
|
|
129 |
worksheet.write(row, inc(), row1[1])
|
| 14474 |
amit.gupta |
130 |
worksheet.write(row, inc(), row1[-1])
|
| 14771 |
amit.gupta |
131 |
worksheet.write(row, inc(), row1[-2])
|
|
|
132 |
worksheet.write(row, inc(), row1[-3])
|
| 14460 |
amit.gupta |
133 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
134 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
135 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
136 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
137 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
138 |
worksheet.write(row, inc(), subOrder['detailedStatus'])
|
|
|
139 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
140 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
|
|
141 |
worksheet.write(row, inc(), subOrder['placedOn'])
|
|
|
142 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
143 |
for aff in affs:
|
| 14647 |
amit.gupta |
144 |
if aff["_id"] not in reconciled_affiliates and aff['subTagId']== order['subTagId']:
|
|
|
145 |
reconciled_affiliates.append(aff["_id"])
|
|
|
146 |
row2 += 1
|
|
|
147 |
i = -1
|
|
|
148 |
worksheet1.write(row2, inc(), orderId)
|
|
|
149 |
worksheet1.write(row2, inc(), row1[1])
|
|
|
150 |
worksheet1.write(row2, inc(), row1[-1])
|
| 14771 |
amit.gupta |
151 |
worksheet1.write(row2, inc(), row1[-2])
|
|
|
152 |
worksheet1.write(row2, inc(), row1[-3])
|
| 14647 |
amit.gupta |
153 |
worksheet1.write(row2, inc(), order['merchantOrderId'])
|
|
|
154 |
worksheet1.write(row2, inc(), subOrder['productTitle'])
|
|
|
155 |
worksheet1.write(row2, inc(), subOrder['amountPaid'])
|
|
|
156 |
worksheet1.write(row2, inc(), subOrder['quantity'])
|
|
|
157 |
worksheet1.write(row2, inc(), subOrder['status'])
|
|
|
158 |
worksheet1.write(row2, inc(), subOrder['detailedStatus'])
|
|
|
159 |
worksheet1.write(row2, inc(), subOrder['cashBackStatus'])
|
|
|
160 |
worksheet1.write(row2, inc(), subOrder['cashBackAmount'])
|
|
|
161 |
worksheet1.write(row2, inc(), subOrder['placedOn'])
|
|
|
162 |
worksheet1.write(row2, inc(), order['subTagId'])
|
|
|
163 |
db.flipkartOrderAffiliateInfo.update(
|
|
|
164 |
{"productCode":subOrder.get("productCode"), "saleDateInt":saleTime, "subTagId":aff['subTagId']},
|
|
|
165 |
{"$set":{"reconciled":True}})
|
|
|
166 |
db.merchantOrder.update({"merchantOrderId":order["merchantOrderId"]},
|
|
|
167 |
{"$set":{"reconciled":True}})
|
| 14460 |
amit.gupta |
168 |
worksheet.write(row, inc(), aff['category'])
|
| 14647 |
amit.gupta |
169 |
worksheet1.write(row2, i, aff['category'])
|
| 14460 |
amit.gupta |
170 |
worksheet.write(row, inc(), aff['payOut'])
|
| 14647 |
amit.gupta |
171 |
worksheet1.write(row2, i, aff['payOut'])
|
| 14460 |
amit.gupta |
172 |
worksheet.write(row, inc(), aff['saleAmount'])
|
| 14647 |
amit.gupta |
173 |
worksheet1.write(row2, i, aff['saleAmount'])
|
| 14460 |
amit.gupta |
174 |
worksheet.write(row, inc(), aff['saleDate'])
|
| 14647 |
amit.gupta |
175 |
worksheet1.write(row2, i, aff['saleDate'])
|
| 14460 |
amit.gupta |
176 |
break
|
| 14647 |
amit.gupta |
177 |
row3 += 1
|
|
|
178 |
i=-1
|
|
|
179 |
worksheet2.write(row3, inc(), orderId)
|
|
|
180 |
worksheet2.write(row3, inc(), row1[1])
|
|
|
181 |
worksheet2.write(row3, inc(), row1[-1])
|
| 14771 |
amit.gupta |
182 |
worksheet2.write(row3, inc(), row1[-2])
|
|
|
183 |
worksheet2.write(row3, inc(), row1[-3])
|
| 14647 |
amit.gupta |
184 |
worksheet2.write(row3, inc(), order['merchantOrderId'])
|
|
|
185 |
worksheet2.write(row3, inc(), subOrder['productTitle'])
|
|
|
186 |
worksheet2.write(row3, inc(), subOrder['amountPaid'])
|
|
|
187 |
worksheet2.write(row3, inc(), subOrder['quantity'])
|
|
|
188 |
worksheet2.write(row3, inc(), subOrder['status'])
|
|
|
189 |
worksheet2.write(row3, inc(), subOrder['detailedStatus'])
|
|
|
190 |
worksheet2.write(row3, inc(), subOrder['cashBackStatus'])
|
|
|
191 |
worksheet2.write(row3, inc(), subOrder['cashBackAmount'])
|
|
|
192 |
worksheet2.write(row3, inc(), subOrder['placedOn'])
|
|
|
193 |
worksheet2.write(row3, inc(), order['subTagId'])
|
|
|
194 |
|
|
|
195 |
i=-1
|
|
|
196 |
worksheet3.write(0, inc(), "category",boldStyle)
|
|
|
197 |
worksheet3.write(0, inc(), "conversionStatus",boldStyle)
|
|
|
198 |
worksheet3.write(0, inc(), "Product Title",boldStyle)
|
|
|
199 |
worksheet3.write(0, inc(), "price",boldStyle)
|
|
|
200 |
worksheet3.write(0, inc(), "quantity",boldStyle)
|
|
|
201 |
worksheet3.write(0, inc(), "payOut",boldStyle)
|
|
|
202 |
worksheet3.write(0, inc(), "saleDate",boldStyle)
|
|
|
203 |
worksheet3.write(0, inc(), "subTagId",boldStyle)
|
|
|
204 |
for aff in db.flipkartOrderAffiliateInfo.find({"reconciled":{"$exists":False}}):
|
|
|
205 |
row4 += 1
|
|
|
206 |
i =-1
|
|
|
207 |
worksheet3.write(row4, inc(), aff["category"])
|
|
|
208 |
worksheet3.write(row4, inc(), aff["conversionStatus"])
|
|
|
209 |
skuData = getSkuData(2, aff["productCode"])
|
|
|
210 |
if skuData is None:
|
|
|
211 |
worksheet3.write(row4, inc(), aff["productTitle"])
|
|
|
212 |
else:
|
|
|
213 |
worksheet3.write(row4, inc(), skuData["product_name"])
|
|
|
214 |
worksheet3.write(row4, inc(), aff['price'])
|
|
|
215 |
worksheet3.write(row4, inc(), aff['quantity'])
|
|
|
216 |
worksheet3.write(row4, inc(), aff['payOut'])
|
|
|
217 |
worksheet3.write(row4, inc(), aff['saleDate'])
|
|
|
218 |
worksheet3.write(row4, inc(), aff['subTagId'])
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
wb.save(XLS_F_FILENAME)
|
| 14450 |
amit.gupta |
223 |
def generateSnapDealReco():
|
| 14524 |
amit.gupta |
224 |
global i
|
| 14460 |
amit.gupta |
225 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 3)
|
| 14450 |
amit.gupta |
226 |
db = client.Dtr
|
| 14524 |
amit.gupta |
227 |
notReconciled = {}
|
| 14487 |
amit.gupta |
228 |
matchedList = []
|
| 14450 |
amit.gupta |
229 |
workbook = xlwt.Workbook()
|
| 14501 |
amit.gupta |
230 |
worksheet = workbook.add_sheet("Snapdeal Reconciled")
|
|
|
231 |
worksheet1 = workbook.add_sheet("Snapdeal Reconciled All")
|
| 14508 |
amit.gupta |
232 |
worksheet2 = workbook.add_sheet("Snapdeal Orders not reconciled")
|
|
|
233 |
affNotReconciledSheet = workbook.add_sheet("Snapdeal Aff not reconciled")
|
|
|
234 |
setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet)
|
| 14450 |
amit.gupta |
235 |
row = 0
|
| 14501 |
amit.gupta |
236 |
anotherrow = 0
|
| 14508 |
amit.gupta |
237 |
row2 = 0
|
| 14450 |
amit.gupta |
238 |
for row1 in curs:
|
|
|
239 |
orderId = row1[0]
|
|
|
240 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
241 |
if order is None:
|
|
|
242 |
continue
|
| 14496 |
amit.gupta |
243 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
| 14450 |
amit.gupta |
244 |
aff = list(db.snapdealOrderAffiliateInfo.find({"subTagId":order["subTagId"]}))
|
| 14501 |
amit.gupta |
245 |
anotherrow += 1
|
| 14524 |
amit.gupta |
246 |
if len(aff) > 0 and order["subTagId"] not in matchedList and int(order["paidAmount"])==int(aff[0]["saleAmount"]):
|
| 14501 |
amit.gupta |
247 |
matchedList.append(order["subTagId"])
|
| 14610 |
amit.gupta |
248 |
db.snapdealOrderAffiliateInfo.update({"adId":aff[0].get("adId")}, {"$set":{"reconciled":True, "orderId":orderId}}, multi=True)
|
| 14501 |
amit.gupta |
249 |
order['reconciled'] = True
|
| 14610 |
amit.gupta |
250 |
order['adId'] = aff[0].get("adId")
|
| 14501 |
amit.gupta |
251 |
db.merchantOrder.save(order)
|
|
|
252 |
row += 1
|
|
|
253 |
i=-1
|
|
|
254 |
worksheet.write(row, inc(), orderId)
|
|
|
255 |
worksheet1.write(anotherrow, i, orderId)
|
|
|
256 |
worksheet.write(row, inc(), row1[1])
|
|
|
257 |
worksheet1.write(anotherrow, i, row1[1])
|
| 14771 |
amit.gupta |
258 |
worksheet.write(row, inc(), row1[-3])
|
|
|
259 |
worksheet1.write(anotherrow, i, row1[-3])
|
| 14601 |
amit.gupta |
260 |
worksheet.write(row, inc(), row1[-2])
|
|
|
261 |
worksheet1.write(anotherrow, i, row1[-2])
|
| 14501 |
amit.gupta |
262 |
worksheet.write(row, inc(), row1[-1])
|
|
|
263 |
worksheet1.write(anotherrow, i, row1[-1])
|
|
|
264 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
265 |
worksheet1.write(anotherrow, i, order['merchantOrderId'])
|
|
|
266 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
267 |
worksheet1.write(anotherrow, i, order['subTagId'])
|
|
|
268 |
worksheet.write(row, inc(), order['placedOn'])
|
|
|
269 |
worksheet1.write(anotherrow, i, order['placedOn'])
|
|
|
270 |
worksheet.write(row, inc(), int(order['paidAmount']))
|
|
|
271 |
worksheet1.write(anotherrow, i, int(order['paidAmount']))
|
| 14524 |
amit.gupta |
272 |
worksheet.write(row, inc(), aff[0]['saleDate'])
|
|
|
273 |
worksheet1.write(anotherrow, i, aff[0]['saleDate'])
|
|
|
274 |
worksheet.write(row, inc(), aff[0]['saleAmount'])
|
|
|
275 |
worksheet1.write(anotherrow, i, aff[0]['saleAmount'])
|
|
|
276 |
worksheet.write(row, inc(), aff[0]['payOut'])
|
|
|
277 |
worksheet1.write(anotherrow, i, aff[0]['payOut'])
|
| 14601 |
amit.gupta |
278 |
worksheet.write(row, inc(), aff[0]['ip'])
|
|
|
279 |
worksheet1.write(anotherrow, i, aff[0]['ip'])
|
| 14501 |
amit.gupta |
280 |
k = i
|
| 14504 |
amit.gupta |
281 |
row -= 1
|
|
|
282 |
anotherrow -= 1
|
| 14501 |
amit.gupta |
283 |
for subOrder in order['subOrders']:
|
|
|
284 |
i = k
|
| 14503 |
amit.gupta |
285 |
row += 1
|
|
|
286 |
anotherrow += 1
|
| 14501 |
amit.gupta |
287 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
288 |
worksheet1.write(anotherrow, i, subOrder['productTitle'])
|
|
|
289 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
290 |
worksheet1.write(anotherrow, i, subOrder['amountPaid'])
|
|
|
291 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
292 |
worksheet1.write(anotherrow, i, subOrder['quantity'])
|
|
|
293 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
294 |
worksheet1.write(anotherrow, i, subOrder['status'])
|
|
|
295 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
296 |
worksheet1.write(anotherrow, i, subOrder['cashBackStatus'])
|
|
|
297 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
|
|
298 |
worksheet1.write(anotherrow, i, subOrder['cashBackAmount'])
|
| 14504 |
amit.gupta |
299 |
|
| 14501 |
amit.gupta |
300 |
else:
|
| 14524 |
amit.gupta |
301 |
i=-1
|
| 14501 |
amit.gupta |
302 |
worksheet1.write(anotherrow, inc(), orderId)
|
|
|
303 |
worksheet1.write(anotherrow, inc(), row1[1])
|
| 14771 |
amit.gupta |
304 |
worksheet1.write(anotherrow, inc(), row1[-3])
|
| 14601 |
amit.gupta |
305 |
worksheet1.write(anotherrow, inc(), row1[-2])
|
| 14501 |
amit.gupta |
306 |
worksheet1.write(anotherrow, inc(), row1[-1])
|
|
|
307 |
worksheet1.write(anotherrow, inc(), order['merchantOrderId'])
|
|
|
308 |
worksheet1.write(anotherrow, inc(), order['subTagId'])
|
|
|
309 |
worksheet1.write(anotherrow, inc(), order['placedOn'])
|
|
|
310 |
worksheet1.write(anotherrow, inc(), int(order['paidAmount']))
|
| 14524 |
amit.gupta |
311 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
|
|
312 |
notReconciled[orderId] = (anotherrow, i, int(order['paidAmount']), timestamp1, order["subTagId"])
|
|
|
313 |
inc()
|
|
|
314 |
inc()
|
|
|
315 |
inc()
|
| 14771 |
amit.gupta |
316 |
inc()
|
| 14501 |
amit.gupta |
317 |
k = i
|
| 14504 |
amit.gupta |
318 |
anotherrow -= 1
|
| 14501 |
amit.gupta |
319 |
for subOrder in order['subOrders']:
|
| 14503 |
amit.gupta |
320 |
anotherrow += 1
|
| 14501 |
amit.gupta |
321 |
i = k
|
| 14505 |
amit.gupta |
322 |
worksheet1.write(anotherrow, inc(), subOrder['productTitle'])
|
|
|
323 |
worksheet1.write(anotherrow, inc(), subOrder['amountPaid'])
|
|
|
324 |
worksheet1.write(anotherrow, inc(), subOrder['quantity'])
|
|
|
325 |
worksheet1.write(anotherrow, inc(), subOrder['status'])
|
|
|
326 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackStatus'])
|
|
|
327 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackAmount'])
|
| 14570 |
amit.gupta |
328 |
|
| 14524 |
amit.gupta |
329 |
|
|
|
330 |
last30Days = date.today() - timedelta(days=30)
|
|
|
331 |
int(time.mktime(last30Days.timetuple()))
|
|
|
332 |
row = 0
|
|
|
333 |
for offer in db.snapdealOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
334 |
"saleTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
335 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
336 |
subTagId = offer.get("subTagId")
|
|
|
337 |
saleTime = offer.get("saleTime")
|
|
|
338 |
orders = getOrdersByTag(subTagId, 3)
|
|
|
339 |
for order in orders:
|
|
|
340 |
if notReconciled.has_key(order[0]):
|
|
|
341 |
(roww, column, paidAmount, timestamp1, oSubTagId) = notReconciled[order[0]]
|
|
|
342 |
if paidAmount==int(offer.get("saleAmount")) and timestamp1 <= saleTime and timestamp1 + 120 >= saleTime:
|
|
|
343 |
i = column
|
| 14570 |
amit.gupta |
344 |
worksheet1.write(roww, inc(), offer.get("saleDate"))
|
| 14527 |
amit.gupta |
345 |
worksheet1.write(roww, inc(), offer.get("saleAmount"))
|
|
|
346 |
worksheet1.write(roww, inc(), offer.get("payOut"))
|
|
|
347 |
del notReconciled[order[0]]
|
| 14530 |
amit.gupta |
348 |
print "found match for user", order[1]
|
| 14610 |
amit.gupta |
349 |
db.snapdealOrderAffiliateInfo.update({"adId":offer.get("adId")}, {"$set":{"reconciled":True, "orderId":order[0]}}, multi=True)
|
|
|
350 |
db.merchantOrder.update({"orderId":order[0]}, {"$set":{"reconciled":True, "adId":offer.get("adId")}}, multi=True)
|
| 14570 |
amit.gupta |
351 |
break
|
| 14530 |
amit.gupta |
352 |
|
| 14570 |
amit.gupta |
353 |
unreconciledOrders = notReconciled.keys()
|
|
|
354 |
row2=0
|
|
|
355 |
for row1 in curs:
|
|
|
356 |
if row1[0] in unreconciledOrders:
|
|
|
357 |
for order in db.merchantOrder.find({"orderId":row1[0]}):
|
|
|
358 |
row2 += 1
|
|
|
359 |
i=-1
|
|
|
360 |
worksheet2.write(row2, inc(), order["orderId"])
|
|
|
361 |
worksheet2.write(row2, inc(), row1[1])
|
| 14771 |
amit.gupta |
362 |
worksheet2.write(row2, inc(), row1[-3])
|
| 14605 |
amit.gupta |
363 |
worksheet2.write(row2, inc(), row1[-2])
|
| 14570 |
amit.gupta |
364 |
worksheet2.write(row2, inc(), row1[-1])
|
|
|
365 |
worksheet2.write(row2, inc(), order['merchantOrderId'])
|
|
|
366 |
worksheet2.write(row2, inc(), order['subTagId'])
|
|
|
367 |
worksheet2.write(row2, inc(), order['placedOn'])
|
|
|
368 |
worksheet2.write(row2, inc(), int(order['paidAmount']))
|
|
|
369 |
row2 -=1
|
|
|
370 |
k=i
|
|
|
371 |
for subOrder in order['subOrders']:
|
|
|
372 |
i = k
|
|
|
373 |
row2 += 1
|
|
|
374 |
worksheet2.write(row2, inc(), subOrder['productTitle'])
|
|
|
375 |
worksheet2.write(row2, inc(), subOrder['amountPaid'])
|
|
|
376 |
worksheet2.write(row2, inc(), subOrder['quantity'])
|
|
|
377 |
worksheet2.write(row2, inc(), subOrder['status'])
|
|
|
378 |
worksheet2.write(row2, inc(), subOrder['cashBackStatus'])
|
|
|
379 |
worksheet2.write(row2, inc(), subOrder['cashBackAmount'])
|
|
|
380 |
|
|
|
381 |
|
|
|
382 |
for offer in db.snapdealOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
383 |
"saleTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
384 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
385 |
row += 1
|
|
|
386 |
i=-1
|
|
|
387 |
affNotReconciledSheet.write(row, inc(), offer.get("adId"))
|
|
|
388 |
affNotReconciledSheet.write(row, inc(), offer.get("subTagId"))
|
|
|
389 |
affNotReconciledSheet.write(row, inc(), offer.get("saleDate"))
|
|
|
390 |
affNotReconciledSheet.write(row, inc(), offer.get("saleAmount"))
|
|
|
391 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
|
|
392 |
affNotReconciledSheet.write(row, inc(), offer.get("conversionStatus"))
|
| 14601 |
amit.gupta |
393 |
affNotReconciledSheet.write(row, inc(), offer.get("ip"))
|
| 14570 |
amit.gupta |
394 |
|
| 14460 |
amit.gupta |
395 |
workbook.save(XLS_FILENAME)
|
| 14450 |
amit.gupta |
396 |
|
| 14647 |
amit.gupta |
397 |
def sendmail(email, message, title, *varargs):
|
| 14450 |
amit.gupta |
398 |
if email == "":
|
|
|
399 |
return
|
|
|
400 |
mailServer = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
|
|
|
401 |
mailServer.ehlo()
|
|
|
402 |
mailServer.starttls()
|
|
|
403 |
mailServer.ehlo()
|
|
|
404 |
|
|
|
405 |
# Create the container (outer) email message.
|
|
|
406 |
msg = MIMEMultipart()
|
|
|
407 |
msg['Subject'] = title
|
|
|
408 |
msg.preamble = title
|
|
|
409 |
html_msg = MIMEText(message, 'html')
|
|
|
410 |
msg.attach(html_msg)
|
|
|
411 |
|
|
|
412 |
#snapdeal more to be added here
|
| 14647 |
amit.gupta |
413 |
for fileName in varargs:
|
|
|
414 |
snapdeal = MIMEBase('application', 'vnd.ms-excel')
|
|
|
415 |
snapdeal.set_payload(file(fileName).read())
|
|
|
416 |
encoders.encode_base64(snapdeal)
|
|
|
417 |
snapdeal.add_header('Content-Disposition', 'attachment;filename=' + fileName)
|
|
|
418 |
msg.attach(snapdeal)
|
| 14450 |
amit.gupta |
419 |
|
|
|
420 |
|
|
|
421 |
email.append('amit.gupta@shop2020.in')
|
|
|
422 |
MAILTO = email
|
|
|
423 |
mailServer.login(SENDER, PASSWORD)
|
|
|
424 |
mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
|
|
|
425 |
|
| 14508 |
amit.gupta |
426 |
def setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet):
|
| 14505 |
amit.gupta |
427 |
boldStyle = xlwt.XFStyle()
|
|
|
428 |
f = xlwt.Font()
|
|
|
429 |
f.bold = True
|
|
|
430 |
boldStyle.font = f
|
| 14501 |
amit.gupta |
431 |
row = 0
|
|
|
432 |
global i
|
|
|
433 |
i=-1
|
|
|
434 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
|
|
435 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
| 14601 |
amit.gupta |
436 |
worksheet.write(row, inc(), 'Version Code', boldStyle)
|
| 14771 |
amit.gupta |
437 |
worksheet.write(row, inc(), 'Device', boldStyle)
|
| 14501 |
amit.gupta |
438 |
worksheet.write(row, inc(), 'Username', boldStyle)
|
|
|
439 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
440 |
worksheet.write(row, inc(), 'SubtagId', boldStyle)
|
|
|
441 |
worksheet.write(row, inc(), 'Sale Date', boldStyle)
|
|
|
442 |
worksheet.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
443 |
worksheet.write(row, inc(), 'Aff Sale Date', boldStyle)
|
|
|
444 |
worksheet.write(row, inc(), 'Aff Sale Amt', boldStyle)
|
|
|
445 |
worksheet.write(row, inc(), 'Aff PayOut', boldStyle)
|
| 14601 |
amit.gupta |
446 |
worksheet.write(row, inc(), 'IP', boldStyle)
|
| 14501 |
amit.gupta |
447 |
worksheet.write(row, inc(), 'Product Title', boldStyle)
|
|
|
448 |
worksheet.write(row, inc(), 'Price', boldStyle)
|
|
|
449 |
worksheet.write(row, inc(), 'Quantity', boldStyle)
|
|
|
450 |
worksheet.write(row, inc(), 'Status', boldStyle)
|
|
|
451 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
452 |
worksheet.write(row, inc(), 'CashBack', boldStyle)
|
|
|
453 |
|
| 14505 |
amit.gupta |
454 |
i = -1
|
| 14501 |
amit.gupta |
455 |
worksheet1.write(row, inc(), 'Order Id', boldStyle)
|
|
|
456 |
worksheet1.write(row, inc(), 'User Id', boldStyle)
|
| 14601 |
amit.gupta |
457 |
worksheet1.write(row, inc(), 'Version Code', boldStyle)
|
| 14771 |
amit.gupta |
458 |
worksheet1.write(row, inc(), 'Device', boldStyle)
|
| 14501 |
amit.gupta |
459 |
worksheet1.write(row, inc(), 'Username', boldStyle)
|
|
|
460 |
worksheet1.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
461 |
worksheet1.write(row, inc(), 'SubtagId', boldStyle)
|
|
|
462 |
worksheet1.write(row, inc(), 'Sale Date', boldStyle)
|
|
|
463 |
worksheet1.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
464 |
worksheet1.write(row, inc(), 'Aff Sale Date', boldStyle)
|
|
|
465 |
worksheet1.write(row, inc(), 'Aff Sale Amt', boldStyle)
|
|
|
466 |
worksheet1.write(row, inc(), 'Aff PayOut', boldStyle)
|
| 14601 |
amit.gupta |
467 |
worksheet1.write(row, inc(), 'IP', boldStyle)
|
| 14501 |
amit.gupta |
468 |
worksheet1.write(row, inc(), 'Product Title', boldStyle)
|
|
|
469 |
worksheet1.write(row, inc(), 'Price', boldStyle)
|
|
|
470 |
worksheet1.write(row, inc(), 'Quantity', boldStyle)
|
|
|
471 |
worksheet1.write(row, inc(), 'Status', boldStyle)
|
|
|
472 |
worksheet1.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
473 |
worksheet1.write(row, inc(), 'CashBack', boldStyle)
|
| 14508 |
amit.gupta |
474 |
|
|
|
475 |
i = -1
|
|
|
476 |
worksheet2.write(row, inc(), 'Order Id', boldStyle)
|
|
|
477 |
worksheet2.write(row, inc(), 'User Id', boldStyle)
|
| 14605 |
amit.gupta |
478 |
worksheet2.write(row, inc(), 'Version Code', boldStyle)
|
| 14771 |
amit.gupta |
479 |
worksheet2.write(row, inc(), 'Device', boldStyle)
|
| 14508 |
amit.gupta |
480 |
worksheet2.write(row, inc(), 'Username', boldStyle)
|
|
|
481 |
worksheet2.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
482 |
worksheet2.write(row, inc(), 'SubtagId', boldStyle)
|
|
|
483 |
worksheet2.write(row, inc(), 'Sale Date', boldStyle)
|
|
|
484 |
worksheet2.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
485 |
worksheet2.write(row, inc(), 'Product Title', boldStyle)
|
|
|
486 |
worksheet2.write(row, inc(), 'Price', boldStyle)
|
|
|
487 |
worksheet2.write(row, inc(), 'Quantity', boldStyle)
|
|
|
488 |
worksheet2.write(row, inc(), 'Status', boldStyle)
|
|
|
489 |
worksheet2.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
490 |
worksheet2.write(row, inc(), 'CashBack', boldStyle)
|
| 14450 |
amit.gupta |
491 |
|
| 14508 |
amit.gupta |
492 |
i =-1
|
|
|
493 |
affNotReconciledSheet.write(row, inc(), 'AdId', boldStyle)
|
|
|
494 |
affNotReconciledSheet.write(row, inc(), 'subTagId', boldStyle)
|
|
|
495 |
affNotReconciledSheet.write(row, inc(), 'Sale Date', boldStyle)
|
|
|
496 |
affNotReconciledSheet.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
497 |
affNotReconciledSheet.write(row, inc(), 'Pay Out', boldStyle)
|
|
|
498 |
affNotReconciledSheet.write(row, inc(), 'Status', boldStyle)
|
| 14601 |
amit.gupta |
499 |
affNotReconciledSheet.write(row, inc(), 'IP', boldStyle)
|
| 14524 |
amit.gupta |
500 |
|
|
|
501 |
def getUserAmountReconciled():
|
|
|
502 |
pass
|
|
|
503 |
|
| 14613 |
amit.gupta |
504 |
def getUserOrders():
|
|
|
505 |
global i
|
|
|
506 |
rb = open_workbook(XLS_FILENAME,formatting_info=True)
|
|
|
507 |
wb = copy(rb)
|
|
|
508 |
worksheet = wb.add_sheet("All Users")
|
|
|
509 |
worksheet1 = wb.add_sheet("Suspected Users")
|
| 14632 |
amit.gupta |
510 |
workbook = xlwt.Workbook()
|
|
|
511 |
sh1 = workbook.add_sheet("All Orders")
|
|
|
512 |
|
| 14613 |
amit.gupta |
513 |
db=client.Dtr
|
|
|
514 |
results = Mysql.fetchResult('''
|
| 14771 |
amit.gupta |
515 |
select ow.*, u.username, crm1.order_count, u.referrer from order_view ow left join users u on u.id = ow.user_id left join (select user_id, count(*) as order_count from order_view where status = 'ORDER_CREATED' group by user_id) as crm1 on ow.user_id = crm1.user_id where lower(u.referrer) not like 'emp%' or u.referrer is null;
|
| 14613 |
amit.gupta |
516 |
''',)
|
|
|
517 |
row = 0
|
|
|
518 |
i=-1
|
|
|
519 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
|
|
520 |
worksheet1.write(row, i, 'User Id', boldStyle)
|
|
|
521 |
worksheet.write(row, inc(), 'User name', boldStyle)
|
|
|
522 |
worksheet1.write(row, i, 'User name', boldStyle)
|
|
|
523 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
|
|
524 |
worksheet1.write(row, i, 'Order Id', boldStyle)
|
|
|
525 |
worksheet.write(row, inc(), 'Created On', boldStyle)
|
|
|
526 |
worksheet1.write(row, i, 'Created On', boldStyle)
|
|
|
527 |
worksheet.write(row, inc(), 'Store Id', boldStyle)
|
|
|
528 |
worksheet1.write(row, i, 'Store Id', boldStyle)
|
|
|
529 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
530 |
worksheet1.write(row, i, 'Merchant Order Id', boldStyle)
|
| 14616 |
amit.gupta |
531 |
worksheet.write(row, inc(), 'Product title', boldStyle)
|
|
|
532 |
worksheet1.write(row, i, 'Product title', boldStyle)
|
| 14613 |
amit.gupta |
533 |
worksheet.write(row, inc(), 'Amount Paid', boldStyle)
|
|
|
534 |
worksheet1.write(row, i, 'Amount Paid', boldStyle)
|
|
|
535 |
worksheet.write(row, inc(), 'Cashback', boldStyle)
|
|
|
536 |
worksheet1.write(row, i, 'Cashback', boldStyle)
|
|
|
537 |
worksheet.write(row, inc(), 'Order Status', boldStyle)
|
|
|
538 |
worksheet1.write(row, i, 'Order Status', boldStyle)
|
|
|
539 |
worksheet.write(row, inc(), 'Detailed Status', boldStyle)
|
|
|
540 |
worksheet1.write(row, i, 'Detailed Status', boldStyle)
|
|
|
541 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
542 |
worksheet1.write(row, i, 'Cashback Status', boldStyle)
|
|
|
543 |
worksheet.write(row, inc(), 'Reconciled', boldStyle)
|
|
|
544 |
worksheet1.write(row, i, 'Reconciled', boldStyle)
|
|
|
545 |
worksheet.write(row, inc(), 'IP', boldStyle)
|
|
|
546 |
worksheet1.write(row, i, 'IP', boldStyle)
|
| 14693 |
amit.gupta |
547 |
i=-1
|
|
|
548 |
sh1.write(row, inc(), 'User Id', boldStyle)
|
|
|
549 |
sh1.write(row, inc(), 'User name', boldStyle)
|
|
|
550 |
sh1.write(row, inc(), 'Order Id', boldStyle)
|
|
|
551 |
sh1.write(row, inc(), 'Created On', boldStyle)
|
|
|
552 |
sh1.write(row, inc(), 'Store Id', boldStyle)
|
|
|
553 |
sh1.write(row, inc(), 'Merchant Order Id', boldStyle)
|
| 14771 |
amit.gupta |
554 |
sh1.write(row, inc(), 'Status', boldStyle)
|
| 14693 |
amit.gupta |
555 |
sh1.write(row, inc(), 'Product title', boldStyle)
|
|
|
556 |
sh1.write(row, inc(), 'Referrer', boldStyle)
|
|
|
557 |
sh1.write(row, inc(), 'Amount Paid', boldStyle)
|
| 14771 |
amit.gupta |
558 |
sh1.write(row, inc(), 'Catalog Id', boldStyle)
|
| 14693 |
amit.gupta |
559 |
sh1.write(row, inc(), 'Brand', boldStyle)
|
|
|
560 |
sh1.write(row, inc(), 'Model', boldStyle)
|
|
|
561 |
sh1.write(row, inc(), 'Category', boldStyle)
|
| 14613 |
amit.gupta |
562 |
|
|
|
563 |
row=0
|
|
|
564 |
row2=0
|
| 14632 |
amit.gupta |
565 |
row3=0
|
|
|
566 |
db1 = client.Catalog
|
| 14613 |
amit.gupta |
567 |
for result in results:
|
|
|
568 |
morder = db.merchantOrder.find_one({"orderId":result[0]})
|
|
|
569 |
if morder is not None:
|
|
|
570 |
subOrders = morder.get("subOrders")
|
|
|
571 |
if subOrders is not None:
|
|
|
572 |
for subOrder in subOrders:
|
| 14632 |
amit.gupta |
573 |
row3+=1
|
|
|
574 |
i=-1
|
| 14699 |
amit.gupta |
575 |
sh1.write(row3, inc(), result[1])
|
|
|
576 |
sh1.write(row3, inc(), result[-3])
|
| 14632 |
amit.gupta |
577 |
sh1.write(row3, inc(), result[0])
|
|
|
578 |
sh1.write(row3, inc(), result[-4], datetime_format)
|
|
|
579 |
sh1.write(row3, inc(), sourceMap.get(result[2]))
|
|
|
580 |
sh1.write(row3, inc(), morder.get("merchantOrderId"))
|
| 14771 |
amit.gupta |
581 |
sh1.write(row3, inc(), subOrder.get("status"))
|
| 14632 |
amit.gupta |
582 |
sh1.write(row3, inc(), subOrder.get("productTitle"))
|
| 14693 |
amit.gupta |
583 |
sh1.write(row3, inc(), result[-1])
|
| 14632 |
amit.gupta |
584 |
inc()
|
|
|
585 |
if int(subOrder.get("quantity")) > 0:
|
|
|
586 |
sh1.write(row3, i, int(subOrder.get("amountPaid"))/int(subOrder.get("quantity")))
|
| 14647 |
amit.gupta |
587 |
skuData = getSkuData(morder.get("storeId"), subOrder.get("productCode"))
|
|
|
588 |
if morder.get("storeId") in (1,2,4,5):
|
|
|
589 |
skuData = db1.MasterData.find_one({'identifier':subOrder.get("productCode").strip(), 'source_id':morder.get("storeId")})
|
|
|
590 |
elif morder.get("storeId") == 3:
|
|
|
591 |
skuData = db1.MasterData.find_one({'secondaryIdentifier':subOrder.get("productCode").strip(), 'source_id':morder.get("storeId")})
|
| 14634 |
amit.gupta |
592 |
if skuData is not None:
|
| 14771 |
amit.gupta |
593 |
sh1.write(row3, inc(), skuData.get("skuBundleId"))
|
| 14634 |
amit.gupta |
594 |
sh1.write(row3, inc(), skuData.get("brand"))
|
|
|
595 |
sh1.write(row3, inc(), skuData.get("model_name"))
|
|
|
596 |
sh1.write(row3, inc(), skuData.get("category"))
|
| 14613 |
amit.gupta |
597 |
if subOrder.get("cashBackStatus") == Store.CB_APPROVED or subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
|
|
598 |
row +=1
|
|
|
599 |
i=-1
|
|
|
600 |
worksheet.write(row, inc(), result[0])
|
|
|
601 |
worksheet.write(row, inc(), result[-3])
|
|
|
602 |
worksheet.write(row, inc(), result[1])
|
| 14616 |
amit.gupta |
603 |
worksheet.write(row, inc(), result[-4], datetime_format)
|
| 14613 |
amit.gupta |
604 |
worksheet.write(row, inc(), result[2])
|
|
|
605 |
worksheet.write(row, inc(), morder.get("merchantOrderId"))
|
| 14616 |
amit.gupta |
606 |
worksheet.write(row, inc(), subOrder.get("productTitle"))
|
| 14613 |
amit.gupta |
607 |
worksheet.write(row, inc(), subOrder.get("amountPaid"))
|
|
|
608 |
worksheet.write(row, inc(), subOrder.get("cashBackAmount"))
|
|
|
609 |
worksheet.write(row, inc(), subOrder.get("status"))
|
|
|
610 |
worksheet.write(row, inc(), subOrder.get("detailedStatus"))
|
|
|
611 |
worksheet.write(row, inc(), subOrder.get("cashBackStatus"))
|
|
|
612 |
worksheet.write(row, inc(), False if morder.get("reconciled") is None else True)
|
|
|
613 |
if morder.get("reconciled") and morder.get("storeId")==3:
|
|
|
614 |
try:
|
|
|
615 |
worksheet.write(row, inc(), db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True}).get("ip"))
|
|
|
616 |
except:
|
|
|
617 |
print "Could not find", morder.get("adId"), "that is reconcired for order", morder.get("orderId")
|
| 14740 |
amit.gupta |
618 |
if result[-2] >= 10:
|
| 14613 |
amit.gupta |
619 |
row2 +=1
|
|
|
620 |
i=-1
|
|
|
621 |
worksheet1.write(row2, inc(), result[0])
|
|
|
622 |
worksheet1.write(row2, inc(), result[-3])
|
|
|
623 |
worksheet1.write(row2, inc(), result[1])
|
| 14616 |
amit.gupta |
624 |
worksheet1.write(row2, inc(), result[-4], datetime_format)
|
| 14613 |
amit.gupta |
625 |
worksheet1.write(row2, inc(), result[2])
|
|
|
626 |
worksheet1.write(row2, inc(), morder.get("merchantOrderId"))
|
| 14616 |
amit.gupta |
627 |
worksheet1.write(row2, inc(), subOrder.get("productTitle"))
|
| 14613 |
amit.gupta |
628 |
worksheet1.write(row2, inc(), subOrder.get("amountPaid"))
|
|
|
629 |
worksheet1.write(row2, inc(), subOrder.get("cashBackAmount"))
|
|
|
630 |
worksheet1.write(row2, inc(), subOrder.get("status"))
|
|
|
631 |
worksheet1.write(row2, inc(), subOrder.get("detailedStatus"))
|
|
|
632 |
worksheet1.write(row2, inc(), subOrder.get("cashBackStatus"))
|
|
|
633 |
worksheet1.write(row2, inc(), False if morder.get("reconciled") is None else True)
|
|
|
634 |
if morder.get("reconciled") and morder.get("storeId")==3:
|
|
|
635 |
try:
|
|
|
636 |
worksheet1.write(row2, inc(), db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True}).get("ip"))
|
|
|
637 |
except:
|
|
|
638 |
print "Could not find", morder.get("adId"), "that is reconcired for order", morder.get("orderId")
|
| 14632 |
amit.gupta |
639 |
|
|
|
640 |
|
| 14613 |
amit.gupta |
641 |
wb.save(XLS_FILENAME)
|
| 14632 |
amit.gupta |
642 |
workbook.save(XLS_O_FILENAME)
|
| 14647 |
amit.gupta |
643 |
|
|
|
644 |
def getSkuData(storeId, identifier):
|
|
|
645 |
if storeId in (1,2,4,5):
|
|
|
646 |
skuData = client.Catalog.MasterData.find_one({'identifier':identifier, 'source_id':storeId})
|
|
|
647 |
elif storeId == 3:
|
|
|
648 |
skuData = client.Catalog.MasterData.find_one({'secondaryIdentifier':identifier, 'source_id':storeId})
|
|
|
649 |
return skuData
|
|
|
650 |
|
| 14460 |
amit.gupta |
651 |
def inc():
|
|
|
652 |
global i
|
|
|
653 |
i+=1
|
|
|
654 |
return i
|
|
|
655 |
|
| 14632 |
amit.gupta |
656 |
def addHeaders(sheet):
|
|
|
657 |
global i
|
|
|
658 |
i = 0
|
|
|
659 |
sheet.write(0, inc(), )
|
| 14450 |
amit.gupta |
660 |
def main():
|
| 14647 |
amit.gupta |
661 |
|
| 14450 |
amit.gupta |
662 |
generateSnapDealReco()
|
| 14647 |
amit.gupta |
663 |
generateFlipkartReco()
|
| 14650 |
amit.gupta |
664 |
generateAmazonReco(XLS_A_FILENAME)
|
| 14613 |
amit.gupta |
665 |
getUserOrders()
|
| 14774 |
amit.gupta |
666 |
sendmail(["amit.gupta@shop2020.in","rajneesh.arora@saholic.com"], "", "Affiliate Reco", XLS_FILENAME, XLS_F_FILENAME, XLS_A_FILENAME)
|
|
|
667 |
sendmail(["amit.gupta@shop2020.in", "rajneesh.arora@saholic.com", "chaitnaya.vats@saholic.com", "manoj.kumar@saholic.com"], "", "All DTR Orders", XLS_O_FILENAME)
|
| 14450 |
amit.gupta |
668 |
|
|
|
669 |
if __name__ == '__main__':
|
| 14460 |
amit.gupta |
670 |
main()
|
|
|
671 |
|