| 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
|
| 15445 |
amit.gupta |
9 |
from dtr.storage import Mysql, DataService
|
| 15932 |
amit.gupta |
10 |
from dtr.storage.DataService import Users, Clicks, FlipkartOrders,\
|
|
|
11 |
All_user_addresses
|
| 14613 |
amit.gupta |
12 |
from dtr.storage.Mysql import getOrdersAfterDate, getOrdersByTag
|
| 15423 |
amit.gupta |
13 |
from dtr.utils.utils import fromTimeStamp
|
|
|
14 |
from elixir import *
|
| 15440 |
amit.gupta |
15 |
from sqlalchemy.sql.expression import func, func, or_
|
| 14450 |
amit.gupta |
16 |
from email import encoders
|
|
|
17 |
from email.mime.base import MIMEBase
|
|
|
18 |
from email.mime.multipart import MIMEMultipart
|
|
|
19 |
from email.mime.text import MIMEText
|
|
|
20 |
from pymongo.mongo_client import MongoClient
|
| 14460 |
amit.gupta |
21 |
from xlrd import open_workbook
|
| 14524 |
amit.gupta |
22 |
from xlutils.copy import copy
|
| 14460 |
amit.gupta |
23 |
from xlwt.Workbook import Workbook
|
| 14450 |
amit.gupta |
24 |
import MySQLdb
|
|
|
25 |
import smtplib
|
|
|
26 |
import time
|
|
|
27 |
import xlwt
|
| 14460 |
amit.gupta |
28 |
#from xlwt import
|
| 14450 |
amit.gupta |
29 |
|
| 15445 |
amit.gupta |
30 |
DataService.initialize()
|
| 14450 |
amit.gupta |
31 |
client = MongoClient('mongodb://localhost:27017/')
|
|
|
32 |
|
|
|
33 |
SENDER = "cnc.center@shop2020.in"
|
|
|
34 |
PASSWORD = "5h0p2o2o"
|
|
|
35 |
SUBJECT = "DTR User Segmentation report for " + date.today().isoformat()
|
|
|
36 |
SMTP_SERVER = "smtp.gmail.com"
|
|
|
37 |
SMTP_PORT = 587
|
|
|
38 |
|
| 14647 |
amit.gupta |
39 |
XLS_FILENAME = "snapdealaffiliatereco.xls"
|
| 14632 |
amit.gupta |
40 |
XLS_O_FILENAME = "allorders.xls"
|
| 14647 |
amit.gupta |
41 |
XLS_F_FILENAME = "flipkartaffiliatereco.xls"
|
| 14650 |
amit.gupta |
42 |
XLS_A_FILENAME = "amazonaffiliatereco.xls"
|
| 15791 |
manish.sha |
43 |
XLS_SC_FILENAME = "shopcluesaffiliatereco.xls"
|
| 14460 |
amit.gupta |
44 |
boldStyle = xlwt.XFStyle()
|
|
|
45 |
f = xlwt.Font()
|
|
|
46 |
f.bold = True
|
|
|
47 |
boldStyle.font = f
|
|
|
48 |
i = -1
|
| 14616 |
amit.gupta |
49 |
|
|
|
50 |
datetime_format = xlwt.XFStyle()
|
|
|
51 |
datetime_format.num_format_str = 'dd/mm/yyyy HH:MM AM/PM'
|
| 15540 |
amit.gupta |
52 |
categoryMap = {3:"Mobiles", 5:"Tablets"}
|
| 14450 |
amit.gupta |
53 |
def generateFlipkartReco():
|
| 14508 |
amit.gupta |
54 |
global i
|
|
|
55 |
i = -1
|
| 14460 |
amit.gupta |
56 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 2)
|
|
|
57 |
db = client.Dtr
|
| 14647 |
amit.gupta |
58 |
wb = xlwt.Workbook()
|
|
|
59 |
#rb = open_workbook(XLS_F_FILENAME)
|
|
|
60 |
#wb = copy(rb)
|
| 14460 |
amit.gupta |
61 |
#wb = xlwt.Workbook()
|
|
|
62 |
row = 0
|
| 14647 |
amit.gupta |
63 |
row2 = 0
|
|
|
64 |
row3 = 0
|
|
|
65 |
row4 = 0
|
|
|
66 |
worksheet = wb.add_sheet("All Orders")
|
|
|
67 |
worksheet1 = wb.add_sheet("Orders Reconciled")
|
|
|
68 |
worksheet2 = wb.add_sheet("Orders not Reconciled")
|
|
|
69 |
worksheet3 = wb.add_sheet("Aff not Reconciled")
|
| 14460 |
amit.gupta |
70 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
| 14647 |
amit.gupta |
71 |
worksheet1.write(row, i, 'Order Id', boldStyle)
|
|
|
72 |
worksheet2.write(row, i, 'Order Id', boldStyle)
|
| 14460 |
amit.gupta |
73 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
| 14647 |
amit.gupta |
74 |
worksheet1.write(row, i, 'User Id', boldStyle)
|
|
|
75 |
worksheet2.write(row, i, 'User Id', boldStyle)
|
| 14474 |
amit.gupta |
76 |
worksheet.write(row, inc(), 'Username', boldStyle)
|
| 14647 |
amit.gupta |
77 |
worksheet1.write(row, i, 'Username', boldStyle)
|
|
|
78 |
worksheet2.write(row, i, 'Username', boldStyle)
|
| 14771 |
amit.gupta |
79 |
worksheet.write(row, inc(), 'Version code', boldStyle)
|
|
|
80 |
worksheet1.write(row, i, 'Version code', boldStyle)
|
|
|
81 |
worksheet2.write(row, i, 'Version code', boldStyle)
|
|
|
82 |
worksheet.write(row, inc(), 'Device', boldStyle)
|
|
|
83 |
worksheet1.write(row, i, 'Device', boldStyle)
|
|
|
84 |
worksheet2.write(row, i, 'Device', boldStyle)
|
| 14460 |
amit.gupta |
85 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
| 14647 |
amit.gupta |
86 |
worksheet1.write(row, i, 'Merchant Order Id', boldStyle)
|
|
|
87 |
worksheet2.write(row, i, 'Merchant Order Id', boldStyle)
|
| 14460 |
amit.gupta |
88 |
worksheet.write(row, inc(), 'Product Title', boldStyle)
|
| 14647 |
amit.gupta |
89 |
worksheet1.write(row, i, 'Product Title', boldStyle)
|
|
|
90 |
worksheet2.write(row, i, 'Product Title', boldStyle)
|
| 14460 |
amit.gupta |
91 |
worksheet.write(row, inc(), 'Price', boldStyle)
|
| 14647 |
amit.gupta |
92 |
worksheet1.write(row, i, 'Price', boldStyle)
|
|
|
93 |
worksheet2.write(row, i, 'Price', boldStyle)
|
| 14460 |
amit.gupta |
94 |
worksheet.write(row, inc(), 'Quantity', boldStyle)
|
| 14647 |
amit.gupta |
95 |
worksheet1.write(row, i, 'Quantity', boldStyle)
|
|
|
96 |
worksheet2.write(row, i, 'Quantity', boldStyle)
|
| 14460 |
amit.gupta |
97 |
worksheet.write(row, inc(), 'Status', boldStyle)
|
| 14647 |
amit.gupta |
98 |
worksheet1.write(row, i, 'Status', boldStyle)
|
|
|
99 |
worksheet2.write(row, i, 'Status', boldStyle)
|
| 14460 |
amit.gupta |
100 |
worksheet.write(row, inc(), 'Detailed Status', boldStyle)
|
| 14647 |
amit.gupta |
101 |
worksheet1.write(row, i, 'Detailed Status', boldStyle)
|
|
|
102 |
worksheet2.write(row, i, 'Detailed Status', boldStyle)
|
| 14460 |
amit.gupta |
103 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
| 14647 |
amit.gupta |
104 |
worksheet1.write(row, i, 'Cashback Status', boldStyle)
|
|
|
105 |
worksheet2.write(row, i, 'Cashback Status', boldStyle)
|
| 14460 |
amit.gupta |
106 |
worksheet.write(row, inc(), 'Our CashBack', boldStyle)
|
| 14647 |
amit.gupta |
107 |
worksheet1.write(row, i, 'Our CashBack', boldStyle)
|
|
|
108 |
worksheet2.write(row, i, 'Our CashBack', boldStyle)
|
|
|
109 |
worksheet.write(row, inc(), 'Sale Date', boldStyle)
|
|
|
110 |
worksheet1.write(row, i, 'Sale Date', boldStyle)
|
|
|
111 |
worksheet2.write(row, i, 'Sale Date', boldStyle)
|
| 14460 |
amit.gupta |
112 |
worksheet.write(row, inc(), 'SubtagId', boldStyle)
|
| 14647 |
amit.gupta |
113 |
worksheet1.write(row, i, 'SubtagId', boldStyle)
|
|
|
114 |
worksheet2.write(row, i, 'SubtagId', boldStyle)
|
| 14460 |
amit.gupta |
115 |
worksheet.write(row, inc(), 'Category', boldStyle)
|
| 14647 |
amit.gupta |
116 |
worksheet1.write(row, i, 'Category', boldStyle)
|
| 14460 |
amit.gupta |
117 |
worksheet.write(row, inc(), 'Aff PayOut', boldStyle)
|
| 14647 |
amit.gupta |
118 |
worksheet1.write(row, i, 'Aff PayOut', boldStyle)
|
| 14460 |
amit.gupta |
119 |
worksheet.write(row, inc(), 'Aff Sale Amount', boldStyle)
|
| 14647 |
amit.gupta |
120 |
worksheet1.write(row, i, 'Aff Sale Amount', boldStyle)
|
| 14460 |
amit.gupta |
121 |
worksheet.write(row, inc(), 'Aff Sale Date', boldStyle)
|
| 14647 |
amit.gupta |
122 |
worksheet1.write(row, i, 'Aff Sale Date', boldStyle)
|
| 14460 |
amit.gupta |
123 |
for row1 in curs:
|
|
|
124 |
orderId = row1[0]
|
|
|
125 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
126 |
if order is None:
|
|
|
127 |
continue
|
|
|
128 |
saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%d %B, %Y %I:%M %p").replace(hour=0, minute=0, second=0, microsecond=0).timetuple()))
|
|
|
129 |
#saleTime1 = int(time.mktime((datetime.strptime(order['placedOn'], "%b %d, %Y %I:%M %p") + timedelta(seconds=-60)).timetuple()))
|
| 14647 |
amit.gupta |
130 |
reconciled_affiliates = []
|
| 14460 |
amit.gupta |
131 |
for subOrder in order['subOrders']:
|
| 14647 |
amit.gupta |
132 |
affs = list(db.flipkartOrderAffiliateInfo.find({"productCode":subOrder.get("productCode"), "saleDateInt":saleTime}))
|
| 14460 |
amit.gupta |
133 |
row += 1
|
|
|
134 |
i=-1
|
|
|
135 |
worksheet.write(row, inc(), orderId)
|
|
|
136 |
worksheet.write(row, inc(), row1[1])
|
| 14474 |
amit.gupta |
137 |
worksheet.write(row, inc(), row1[-1])
|
| 14771 |
amit.gupta |
138 |
worksheet.write(row, inc(), row1[-2])
|
|
|
139 |
worksheet.write(row, inc(), row1[-3])
|
| 14460 |
amit.gupta |
140 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
141 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
142 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
143 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
144 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
145 |
worksheet.write(row, inc(), subOrder['detailedStatus'])
|
|
|
146 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
147 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
|
|
148 |
worksheet.write(row, inc(), subOrder['placedOn'])
|
|
|
149 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
150 |
for aff in affs:
|
| 14647 |
amit.gupta |
151 |
if aff["_id"] not in reconciled_affiliates and aff['subTagId']== order['subTagId']:
|
|
|
152 |
reconciled_affiliates.append(aff["_id"])
|
|
|
153 |
row2 += 1
|
|
|
154 |
i = -1
|
|
|
155 |
worksheet1.write(row2, inc(), orderId)
|
|
|
156 |
worksheet1.write(row2, inc(), row1[1])
|
|
|
157 |
worksheet1.write(row2, inc(), row1[-1])
|
| 14771 |
amit.gupta |
158 |
worksheet1.write(row2, inc(), row1[-2])
|
|
|
159 |
worksheet1.write(row2, inc(), row1[-3])
|
| 14647 |
amit.gupta |
160 |
worksheet1.write(row2, inc(), order['merchantOrderId'])
|
|
|
161 |
worksheet1.write(row2, inc(), subOrder['productTitle'])
|
|
|
162 |
worksheet1.write(row2, inc(), subOrder['amountPaid'])
|
|
|
163 |
worksheet1.write(row2, inc(), subOrder['quantity'])
|
|
|
164 |
worksheet1.write(row2, inc(), subOrder['status'])
|
|
|
165 |
worksheet1.write(row2, inc(), subOrder['detailedStatus'])
|
|
|
166 |
worksheet1.write(row2, inc(), subOrder['cashBackStatus'])
|
|
|
167 |
worksheet1.write(row2, inc(), subOrder['cashBackAmount'])
|
|
|
168 |
worksheet1.write(row2, inc(), subOrder['placedOn'])
|
|
|
169 |
worksheet1.write(row2, inc(), order['subTagId'])
|
|
|
170 |
db.flipkartOrderAffiliateInfo.update(
|
|
|
171 |
{"productCode":subOrder.get("productCode"), "saleDateInt":saleTime, "subTagId":aff['subTagId']},
|
|
|
172 |
{"$set":{"reconciled":True}})
|
|
|
173 |
db.merchantOrder.update({"merchantOrderId":order["merchantOrderId"]},
|
|
|
174 |
{"$set":{"reconciled":True}})
|
| 14460 |
amit.gupta |
175 |
worksheet.write(row, inc(), aff['category'])
|
| 14647 |
amit.gupta |
176 |
worksheet1.write(row2, i, aff['category'])
|
| 14460 |
amit.gupta |
177 |
worksheet.write(row, inc(), aff['payOut'])
|
| 14647 |
amit.gupta |
178 |
worksheet1.write(row2, i, aff['payOut'])
|
| 14460 |
amit.gupta |
179 |
worksheet.write(row, inc(), aff['saleAmount'])
|
| 14647 |
amit.gupta |
180 |
worksheet1.write(row2, i, aff['saleAmount'])
|
| 14460 |
amit.gupta |
181 |
worksheet.write(row, inc(), aff['saleDate'])
|
| 14647 |
amit.gupta |
182 |
worksheet1.write(row2, i, aff['saleDate'])
|
| 14460 |
amit.gupta |
183 |
break
|
| 14647 |
amit.gupta |
184 |
row3 += 1
|
|
|
185 |
i=-1
|
|
|
186 |
worksheet2.write(row3, inc(), orderId)
|
|
|
187 |
worksheet2.write(row3, inc(), row1[1])
|
|
|
188 |
worksheet2.write(row3, inc(), row1[-1])
|
| 14771 |
amit.gupta |
189 |
worksheet2.write(row3, inc(), row1[-2])
|
|
|
190 |
worksheet2.write(row3, inc(), row1[-3])
|
| 14647 |
amit.gupta |
191 |
worksheet2.write(row3, inc(), order['merchantOrderId'])
|
|
|
192 |
worksheet2.write(row3, inc(), subOrder['productTitle'])
|
|
|
193 |
worksheet2.write(row3, inc(), subOrder['amountPaid'])
|
|
|
194 |
worksheet2.write(row3, inc(), subOrder['quantity'])
|
|
|
195 |
worksheet2.write(row3, inc(), subOrder['status'])
|
|
|
196 |
worksheet2.write(row3, inc(), subOrder['detailedStatus'])
|
|
|
197 |
worksheet2.write(row3, inc(), subOrder['cashBackStatus'])
|
|
|
198 |
worksheet2.write(row3, inc(), subOrder['cashBackAmount'])
|
|
|
199 |
worksheet2.write(row3, inc(), subOrder['placedOn'])
|
|
|
200 |
worksheet2.write(row3, inc(), order['subTagId'])
|
|
|
201 |
|
|
|
202 |
i=-1
|
|
|
203 |
worksheet3.write(0, inc(), "category",boldStyle)
|
|
|
204 |
worksheet3.write(0, inc(), "conversionStatus",boldStyle)
|
|
|
205 |
worksheet3.write(0, inc(), "Product Title",boldStyle)
|
|
|
206 |
worksheet3.write(0, inc(), "price",boldStyle)
|
|
|
207 |
worksheet3.write(0, inc(), "quantity",boldStyle)
|
|
|
208 |
worksheet3.write(0, inc(), "payOut",boldStyle)
|
|
|
209 |
worksheet3.write(0, inc(), "saleDate",boldStyle)
|
|
|
210 |
worksheet3.write(0, inc(), "subTagId",boldStyle)
|
|
|
211 |
for aff in db.flipkartOrderAffiliateInfo.find({"reconciled":{"$exists":False}}):
|
|
|
212 |
row4 += 1
|
|
|
213 |
i =-1
|
|
|
214 |
worksheet3.write(row4, inc(), aff["category"])
|
|
|
215 |
worksheet3.write(row4, inc(), aff["conversionStatus"])
|
|
|
216 |
skuData = getSkuData(2, aff["productCode"])
|
|
|
217 |
if skuData is None:
|
|
|
218 |
worksheet3.write(row4, inc(), aff["productTitle"])
|
|
|
219 |
else:
|
|
|
220 |
worksheet3.write(row4, inc(), skuData["product_name"])
|
|
|
221 |
worksheet3.write(row4, inc(), aff['price'])
|
|
|
222 |
worksheet3.write(row4, inc(), aff['quantity'])
|
|
|
223 |
worksheet3.write(row4, inc(), aff['payOut'])
|
|
|
224 |
worksheet3.write(row4, inc(), aff['saleDate'])
|
|
|
225 |
worksheet3.write(row4, inc(), aff['subTagId'])
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
|
|
|
229 |
wb.save(XLS_F_FILENAME)
|
| 14450 |
amit.gupta |
230 |
def generateSnapDealReco():
|
| 14524 |
amit.gupta |
231 |
global i
|
| 14460 |
amit.gupta |
232 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 3)
|
| 14450 |
amit.gupta |
233 |
db = client.Dtr
|
| 14524 |
amit.gupta |
234 |
notReconciled = {}
|
| 14487 |
amit.gupta |
235 |
matchedList = []
|
| 14450 |
amit.gupta |
236 |
workbook = xlwt.Workbook()
|
| 14501 |
amit.gupta |
237 |
worksheet = workbook.add_sheet("Snapdeal Reconciled")
|
|
|
238 |
worksheet1 = workbook.add_sheet("Snapdeal Reconciled All")
|
| 14508 |
amit.gupta |
239 |
worksheet2 = workbook.add_sheet("Snapdeal Orders not reconciled")
|
|
|
240 |
affNotReconciledSheet = workbook.add_sheet("Snapdeal Aff not reconciled")
|
|
|
241 |
setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet)
|
| 14450 |
amit.gupta |
242 |
row = 0
|
| 14501 |
amit.gupta |
243 |
anotherrow = 0
|
| 14508 |
amit.gupta |
244 |
row2 = 0
|
| 15577 |
amit.gupta |
245 |
row5=0
|
| 14450 |
amit.gupta |
246 |
for row1 in curs:
|
|
|
247 |
orderId = row1[0]
|
|
|
248 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
249 |
if order is None:
|
|
|
250 |
continue
|
| 14496 |
amit.gupta |
251 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
| 14450 |
amit.gupta |
252 |
aff = list(db.snapdealOrderAffiliateInfo.find({"subTagId":order["subTagId"]}))
|
| 14501 |
amit.gupta |
253 |
anotherrow += 1
|
| 14988 |
amit.gupta |
254 |
try:
|
|
|
255 |
formattedTimestamp = order['placedOn']
|
|
|
256 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
|
|
257 |
except:
|
|
|
258 |
timestamp1 = int(time.mktime(row1[-4].timetuple()))
|
|
|
259 |
formattedTimestamp = datetime.strftime(fromTimeStamp(timestamp1), "%b %d, %Y, %I:%M %p")
|
| 14524 |
amit.gupta |
260 |
if len(aff) > 0 and order["subTagId"] not in matchedList and int(order["paidAmount"])==int(aff[0]["saleAmount"]):
|
| 14501 |
amit.gupta |
261 |
matchedList.append(order["subTagId"])
|
| 14610 |
amit.gupta |
262 |
db.snapdealOrderAffiliateInfo.update({"adId":aff[0].get("adId")}, {"$set":{"reconciled":True, "orderId":orderId}}, multi=True)
|
| 14501 |
amit.gupta |
263 |
order['reconciled'] = True
|
| 14610 |
amit.gupta |
264 |
order['adId'] = aff[0].get("adId")
|
| 14501 |
amit.gupta |
265 |
db.merchantOrder.save(order)
|
|
|
266 |
row += 1
|
|
|
267 |
i=-1
|
|
|
268 |
worksheet.write(row, inc(), orderId)
|
|
|
269 |
worksheet1.write(anotherrow, i, orderId)
|
|
|
270 |
worksheet.write(row, inc(), row1[1])
|
|
|
271 |
worksheet1.write(anotherrow, i, row1[1])
|
| 14850 |
amit.gupta |
272 |
worksheet.write(row, inc(), row1[-1])
|
|
|
273 |
worksheet1.write(anotherrow, i, row1[-1])
|
|
|
274 |
worksheet.write(row, inc(), row1[-2])
|
|
|
275 |
worksheet1.write(anotherrow, i, row1[-2])
|
| 14771 |
amit.gupta |
276 |
worksheet.write(row, inc(), row1[-3])
|
|
|
277 |
worksheet1.write(anotherrow, i, row1[-3])
|
| 14501 |
amit.gupta |
278 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
279 |
worksheet1.write(anotherrow, i, order['merchantOrderId'])
|
|
|
280 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
281 |
worksheet1.write(anotherrow, i, order['subTagId'])
|
|
|
282 |
worksheet.write(row, inc(), order['placedOn'])
|
|
|
283 |
worksheet1.write(anotherrow, i, order['placedOn'])
|
| 14988 |
amit.gupta |
284 |
worksheet.write(row, inc(), formattedTimestamp)
|
|
|
285 |
worksheet1.write(anotherrow, i, formattedTimestamp)
|
| 14501 |
amit.gupta |
286 |
worksheet.write(row, inc(), int(order['paidAmount']))
|
|
|
287 |
worksheet1.write(anotherrow, i, int(order['paidAmount']))
|
| 14524 |
amit.gupta |
288 |
worksheet.write(row, inc(), aff[0]['saleDate'])
|
|
|
289 |
worksheet1.write(anotherrow, i, aff[0]['saleDate'])
|
|
|
290 |
worksheet.write(row, inc(), aff[0]['saleAmount'])
|
|
|
291 |
worksheet1.write(anotherrow, i, aff[0]['saleAmount'])
|
|
|
292 |
worksheet.write(row, inc(), aff[0]['payOut'])
|
|
|
293 |
worksheet1.write(anotherrow, i, aff[0]['payOut'])
|
| 14601 |
amit.gupta |
294 |
worksheet.write(row, inc(), aff[0]['ip'])
|
|
|
295 |
worksheet1.write(anotherrow, i, aff[0]['ip'])
|
| 14501 |
amit.gupta |
296 |
k = i
|
| 14504 |
amit.gupta |
297 |
row -= 1
|
|
|
298 |
anotherrow -= 1
|
| 14501 |
amit.gupta |
299 |
for subOrder in order['subOrders']:
|
|
|
300 |
i = k
|
| 14503 |
amit.gupta |
301 |
row += 1
|
|
|
302 |
anotherrow += 1
|
| 14501 |
amit.gupta |
303 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
304 |
worksheet1.write(anotherrow, i, subOrder['productTitle'])
|
|
|
305 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
306 |
worksheet1.write(anotherrow, i, subOrder['amountPaid'])
|
|
|
307 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
308 |
worksheet1.write(anotherrow, i, subOrder['quantity'])
|
|
|
309 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
310 |
worksheet1.write(anotherrow, i, subOrder['status'])
|
|
|
311 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
312 |
worksheet1.write(anotherrow, i, subOrder['cashBackStatus'])
|
|
|
313 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
|
|
314 |
worksheet1.write(anotherrow, i, subOrder['cashBackAmount'])
|
| 14504 |
amit.gupta |
315 |
|
| 14501 |
amit.gupta |
316 |
else:
|
| 14524 |
amit.gupta |
317 |
i=-1
|
| 14501 |
amit.gupta |
318 |
worksheet1.write(anotherrow, inc(), orderId)
|
|
|
319 |
worksheet1.write(anotherrow, inc(), row1[1])
|
| 14850 |
amit.gupta |
320 |
worksheet1.write(anotherrow, inc(), row1[-1])
|
|
|
321 |
worksheet1.write(anotherrow, inc(), row1[-2])
|
| 14771 |
amit.gupta |
322 |
worksheet1.write(anotherrow, inc(), row1[-3])
|
| 14501 |
amit.gupta |
323 |
worksheet1.write(anotherrow, inc(), order['merchantOrderId'])
|
|
|
324 |
worksheet1.write(anotherrow, inc(), order['subTagId'])
|
|
|
325 |
worksheet1.write(anotherrow, inc(), order['placedOn'])
|
| 15576 |
amit.gupta |
326 |
worksheet1.write(anotherrow, inc(), formattedTimestamp)
|
| 14501 |
amit.gupta |
327 |
worksheet1.write(anotherrow, inc(), int(order['paidAmount']))
|
| 14873 |
amit.gupta |
328 |
|
| 14524 |
amit.gupta |
329 |
notReconciled[orderId] = (anotherrow, i, int(order['paidAmount']), timestamp1, order["subTagId"])
|
|
|
330 |
inc()
|
|
|
331 |
inc()
|
|
|
332 |
inc()
|
| 14771 |
amit.gupta |
333 |
inc()
|
| 14501 |
amit.gupta |
334 |
k = i
|
| 14504 |
amit.gupta |
335 |
anotherrow -= 1
|
| 14501 |
amit.gupta |
336 |
for subOrder in order['subOrders']:
|
| 14503 |
amit.gupta |
337 |
anotherrow += 1
|
| 14501 |
amit.gupta |
338 |
i = k
|
| 14505 |
amit.gupta |
339 |
worksheet1.write(anotherrow, inc(), subOrder['productTitle'])
|
|
|
340 |
worksheet1.write(anotherrow, inc(), subOrder['amountPaid'])
|
|
|
341 |
worksheet1.write(anotherrow, inc(), subOrder['quantity'])
|
|
|
342 |
worksheet1.write(anotherrow, inc(), subOrder['status'])
|
|
|
343 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackStatus'])
|
|
|
344 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackAmount'])
|
| 15577 |
amit.gupta |
345 |
row5 += 1
|
|
|
346 |
i=-1
|
|
|
347 |
worksheet2.write(row5, inc(), order["orderId"])
|
|
|
348 |
worksheet2.write(row5, inc(), row1[1])
|
|
|
349 |
worksheet2.write(row5, inc(), row1[-1])
|
|
|
350 |
worksheet2.write(row5, inc(), row1[-2])
|
|
|
351 |
worksheet2.write(row5, inc(), row1[-3])
|
|
|
352 |
worksheet2.write(row5, inc(), order['merchantOrderId'])
|
|
|
353 |
worksheet2.write(row5, inc(), order['subTagId'])
|
|
|
354 |
worksheet2.write(row5, inc(), order['placedOn'])
|
|
|
355 |
worksheet2.write(row5, inc(), formattedTimestamp)
|
|
|
356 |
worksheet2.write(row5, inc(), int(order['paidAmount']))
|
|
|
357 |
row5 -=1
|
|
|
358 |
k=i
|
|
|
359 |
for subOrder in order['subOrders']:
|
|
|
360 |
i = k
|
| 15578 |
amit.gupta |
361 |
row5 += 1
|
| 15577 |
amit.gupta |
362 |
worksheet2.write(row5, inc(), subOrder['productTitle'])
|
|
|
363 |
worksheet2.write(row5, inc(), subOrder['amountPaid'])
|
|
|
364 |
worksheet2.write(row5, inc(), subOrder['quantity'])
|
|
|
365 |
worksheet2.write(row5, inc(), subOrder['status'])
|
|
|
366 |
worksheet2.write(row5, inc(), subOrder['cashBackStatus'])
|
| 15578 |
amit.gupta |
367 |
worksheet2.write(row5, inc(), subOrder['cashBackAmount'])
|
| 14524 |
amit.gupta |
368 |
|
|
|
369 |
last30Days = date.today() - timedelta(days=30)
|
|
|
370 |
int(time.mktime(last30Days.timetuple()))
|
|
|
371 |
row = 0
|
|
|
372 |
for offer in db.snapdealOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
373 |
"saleTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
374 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
375 |
subTagId = offer.get("subTagId")
|
|
|
376 |
saleTime = offer.get("saleTime")
|
|
|
377 |
orders = getOrdersByTag(subTagId, 3)
|
|
|
378 |
for order in orders:
|
|
|
379 |
if notReconciled.has_key(order[0]):
|
|
|
380 |
(roww, column, paidAmount, timestamp1, oSubTagId) = notReconciled[order[0]]
|
|
|
381 |
if paidAmount==int(offer.get("saleAmount")) and timestamp1 <= saleTime and timestamp1 + 120 >= saleTime:
|
|
|
382 |
i = column
|
| 14570 |
amit.gupta |
383 |
worksheet1.write(roww, inc(), offer.get("saleDate"))
|
| 14527 |
amit.gupta |
384 |
worksheet1.write(roww, inc(), offer.get("saleAmount"))
|
|
|
385 |
worksheet1.write(roww, inc(), offer.get("payOut"))
|
|
|
386 |
del notReconciled[order[0]]
|
| 14530 |
amit.gupta |
387 |
print "found match for user", order[1]
|
| 14610 |
amit.gupta |
388 |
db.snapdealOrderAffiliateInfo.update({"adId":offer.get("adId")}, {"$set":{"reconciled":True, "orderId":order[0]}}, multi=True)
|
|
|
389 |
db.merchantOrder.update({"orderId":order[0]}, {"$set":{"reconciled":True, "adId":offer.get("adId")}}, multi=True)
|
| 14570 |
amit.gupta |
390 |
break
|
| 14530 |
amit.gupta |
391 |
|
| 14570 |
amit.gupta |
392 |
unreconciledOrders = notReconciled.keys()
|
| 15577 |
amit.gupta |
393 |
|
| 14570 |
amit.gupta |
394 |
|
|
|
395 |
|
|
|
396 |
for offer in db.snapdealOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
397 |
"saleTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
398 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
399 |
row += 1
|
|
|
400 |
i=-1
|
|
|
401 |
affNotReconciledSheet.write(row, inc(), offer.get("adId"))
|
|
|
402 |
affNotReconciledSheet.write(row, inc(), offer.get("subTagId"))
|
|
|
403 |
affNotReconciledSheet.write(row, inc(), offer.get("saleDate"))
|
|
|
404 |
affNotReconciledSheet.write(row, inc(), offer.get("saleAmount"))
|
|
|
405 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
|
|
406 |
affNotReconciledSheet.write(row, inc(), offer.get("conversionStatus"))
|
| 14601 |
amit.gupta |
407 |
affNotReconciledSheet.write(row, inc(), offer.get("ip"))
|
| 14570 |
amit.gupta |
408 |
|
| 15540 |
amit.gupta |
409 |
workbook.save(XLS_FILENAME)
|
| 15791 |
manish.sha |
410 |
|
|
|
411 |
def generateShopcluesReco():
|
|
|
412 |
global i
|
|
|
413 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 3)
|
|
|
414 |
db = client.Dtr
|
|
|
415 |
notReconciled = {}
|
|
|
416 |
matchedList = []
|
|
|
417 |
workbook = xlwt.Workbook()
|
|
|
418 |
worksheet = workbook.add_sheet("Shopclues Reconciled")
|
|
|
419 |
worksheet1 = workbook.add_sheet("Shopclues Reconciled All")
|
|
|
420 |
worksheet2 = workbook.add_sheet("Shopclues Orders not reconciled")
|
|
|
421 |
affNotReconciledSheet = workbook.add_sheet("Shopclues Aff not reconciled")
|
|
|
422 |
setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet)
|
|
|
423 |
row = 0
|
|
|
424 |
anotherrow = 0
|
|
|
425 |
row2 = 0
|
|
|
426 |
row5=0
|
|
|
427 |
|
|
|
428 |
for row1 in curs:
|
|
|
429 |
orderId = row1[0]
|
|
|
430 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
431 |
if order is None:
|
|
|
432 |
continue
|
|
|
433 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple())) 26 May 2015 02:12 PM
|
| 16204 |
manish.sha |
434 |
aff = list(db.shopcluesOrderAffiliateInfo.find({"merchantOrderId":order["merchantOrderId"]}))
|
| 15791 |
manish.sha |
435 |
anotherrow += 1
|
|
|
436 |
try:
|
|
|
437 |
formattedTimestamp = order['placedOn']
|
|
|
438 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%d %b %Y %I:%M %p").timetuple()))
|
|
|
439 |
except:
|
|
|
440 |
timestamp1 = int(time.mktime(row1[-4].timetuple()))
|
|
|
441 |
formattedTimestamp = datetime.strftime(fromTimeStamp(timestamp1), "%d %b %Y %I:%M %p")
|
|
|
442 |
|
|
|
443 |
if len(aff) > 0 and order["subTagId"] not in matchedList and long(order["paidAmount"])==long(float(aff[0]["transactionValue"])):
|
|
|
444 |
matchedList.append(order["subTagId"])
|
| 16204 |
manish.sha |
445 |
db.shopcluesOrderAffiliateInfo.update({"merchantOrderId":aff[0].get("merchantOrderId")}, {"$set":{"reconciled":True, "orderId":orderId}}, multi=True)
|
| 15791 |
manish.sha |
446 |
order['reconciled'] = True
|
|
|
447 |
order['adId'] = aff[0].get("uniqueKey")
|
|
|
448 |
db.merchantOrder.save(order)
|
|
|
449 |
row += 1
|
|
|
450 |
i=-1
|
| 14450 |
amit.gupta |
451 |
|
| 15791 |
manish.sha |
452 |
worksheet.write(row, inc(), orderId)
|
|
|
453 |
worksheet1.write(anotherrow, i, orderId)
|
|
|
454 |
worksheet.write(row, inc(), row1[1])
|
|
|
455 |
worksheet1.write(anotherrow, i, row1[1])
|
|
|
456 |
worksheet.write(row, inc(), row1[-1])
|
|
|
457 |
worksheet1.write(anotherrow, i, row1[-1])
|
|
|
458 |
worksheet.write(row, inc(), row1[-2])
|
|
|
459 |
worksheet1.write(anotherrow, i, row1[-2])
|
|
|
460 |
worksheet.write(row, inc(), row1[-3])
|
|
|
461 |
worksheet1.write(anotherrow, i, row1[-3])
|
|
|
462 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
463 |
worksheet1.write(anotherrow, i, order['merchantOrderId'])
|
|
|
464 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
465 |
worksheet1.write(anotherrow, i, order['subTagId'])
|
|
|
466 |
worksheet.write(row, inc(), order['placedOn'])
|
|
|
467 |
worksheet1.write(anotherrow, i, order['placedOn'])
|
|
|
468 |
worksheet.write(row, inc(), formattedTimestamp)
|
|
|
469 |
worksheet1.write(anotherrow, i, formattedTimestamp)
|
|
|
470 |
worksheet.write(row, inc(), int(order['paidAmount']))
|
|
|
471 |
worksheet1.write(anotherrow, i, int(order['paidAmount']))
|
|
|
472 |
worksheet.write(row, inc(), datetime.strftime(fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
|
|
473 |
worksheet1.write(anotherrow, i, datetime.strftime(fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
|
|
474 |
worksheet.write(row, inc(), aff[0]['transactionValue'])
|
|
|
475 |
worksheet1.write(anotherrow, i, aff[0]['transactionValue'])
|
|
|
476 |
worksheet.write(row, inc(), aff[0]['payOut'])
|
|
|
477 |
worksheet1.write(anotherrow, i, aff[0]['payOut'])
|
|
|
478 |
worksheet.write(row, inc(), aff[0]['ip'])
|
|
|
479 |
worksheet1.write(anotherrow, i, aff[0]['ip'])
|
|
|
480 |
k = i
|
|
|
481 |
row -= 1
|
|
|
482 |
anotherrow -= 1
|
|
|
483 |
for subOrder in order['subOrders']:
|
|
|
484 |
i = k
|
|
|
485 |
row += 1
|
|
|
486 |
anotherrow += 1
|
|
|
487 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
488 |
worksheet1.write(anotherrow, i, subOrder['productTitle'])
|
|
|
489 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
490 |
worksheet1.write(anotherrow, i, subOrder['amountPaid'])
|
|
|
491 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
492 |
worksheet1.write(anotherrow, i, subOrder['quantity'])
|
|
|
493 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
494 |
worksheet1.write(anotherrow, i, subOrder['status'])
|
|
|
495 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
496 |
worksheet1.write(anotherrow, i, subOrder['cashBackStatus'])
|
|
|
497 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
|
|
498 |
worksheet1.write(anotherrow, i, subOrder['cashBackAmount'])
|
|
|
499 |
|
|
|
500 |
else:
|
|
|
501 |
i=-1
|
|
|
502 |
worksheet1.write(anotherrow, inc(), orderId)
|
|
|
503 |
worksheet1.write(anotherrow, inc(), row1[1])
|
|
|
504 |
worksheet1.write(anotherrow, inc(), row1[-1])
|
|
|
505 |
worksheet1.write(anotherrow, inc(), row1[-2])
|
|
|
506 |
worksheet1.write(anotherrow, inc(), row1[-3])
|
|
|
507 |
worksheet1.write(anotherrow, inc(), order['merchantOrderId'])
|
|
|
508 |
worksheet1.write(anotherrow, inc(), order['subTagId'])
|
|
|
509 |
worksheet1.write(anotherrow, inc(), order['placedOn'])
|
|
|
510 |
worksheet1.write(anotherrow, inc(), formattedTimestamp)
|
|
|
511 |
worksheet1.write(anotherrow, inc(), int(order['paidAmount']))
|
|
|
512 |
|
|
|
513 |
notReconciled[orderId] = (anotherrow, i, int(order['paidAmount']), timestamp1, order["subTagId"])
|
|
|
514 |
inc()
|
|
|
515 |
inc()
|
|
|
516 |
inc()
|
|
|
517 |
inc()
|
|
|
518 |
k = i
|
|
|
519 |
anotherrow -= 1
|
|
|
520 |
for subOrder in order['subOrders']:
|
|
|
521 |
anotherrow += 1
|
|
|
522 |
i = k
|
|
|
523 |
worksheet1.write(anotherrow, inc(), subOrder['productTitle'])
|
|
|
524 |
worksheet1.write(anotherrow, inc(), subOrder['amountPaid'])
|
|
|
525 |
worksheet1.write(anotherrow, inc(), subOrder['quantity'])
|
|
|
526 |
worksheet1.write(anotherrow, inc(), subOrder['status'])
|
|
|
527 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackStatus'])
|
|
|
528 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackAmount'])
|
|
|
529 |
row5 += 1
|
|
|
530 |
i=-1
|
|
|
531 |
worksheet2.write(row5, inc(), order["orderId"])
|
|
|
532 |
worksheet2.write(row5, inc(), row1[1])
|
|
|
533 |
worksheet2.write(row5, inc(), row1[-1])
|
|
|
534 |
worksheet2.write(row5, inc(), row1[-2])
|
|
|
535 |
worksheet2.write(row5, inc(), row1[-3])
|
|
|
536 |
worksheet2.write(row5, inc(), order['merchantOrderId'])
|
|
|
537 |
worksheet2.write(row5, inc(), order['subTagId'])
|
|
|
538 |
worksheet2.write(row5, inc(), order['placedOn'])
|
|
|
539 |
worksheet2.write(row5, inc(), formattedTimestamp)
|
|
|
540 |
worksheet2.write(row5, inc(), int(order['paidAmount']))
|
|
|
541 |
row5 -=1
|
|
|
542 |
k=i
|
|
|
543 |
for subOrder in order['subOrders']:
|
|
|
544 |
i = k
|
|
|
545 |
row5 += 1
|
|
|
546 |
worksheet2.write(row5, inc(), subOrder['productTitle'])
|
|
|
547 |
worksheet2.write(row5, inc(), subOrder['amountPaid'])
|
|
|
548 |
worksheet2.write(row5, inc(), subOrder['quantity'])
|
|
|
549 |
worksheet2.write(row5, inc(), subOrder['status'])
|
|
|
550 |
worksheet2.write(row5, inc(), subOrder['cashBackStatus'])
|
|
|
551 |
worksheet2.write(row5, inc(), subOrder['cashBackAmount'])
|
|
|
552 |
|
|
|
553 |
last30Days = date.today() - timedelta(days=30)
|
|
|
554 |
int(time.mktime(last30Days.timetuple()))
|
|
|
555 |
row = 0
|
|
|
556 |
for offer in db.shopcluesOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
557 |
"transactionTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
558 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
559 |
subTagId = offer.get("subTagId")
|
|
|
560 |
saleTime = offer.get("transactionTime")
|
| 15794 |
manish.sha |
561 |
orders = getOrdersByTag(subTagId, 5)
|
| 15791 |
manish.sha |
562 |
for order in orders:
|
|
|
563 |
if notReconciled.has_key(order[0]):
|
|
|
564 |
(roww, column, paidAmount, timestamp1, oSubTagId) = notReconciled[order[0]]
|
|
|
565 |
if paidAmount==int(offer.get("transactionValue")) and timestamp1 <= saleTime and timestamp1 + 120 >= saleTime:
|
|
|
566 |
i = column
|
|
|
567 |
worksheet1.write(roww, inc(), datetime.strftime(fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
|
|
568 |
worksheet1.write(roww, inc(), offer.get("transactionValue"))
|
|
|
569 |
worksheet1.write(roww, inc(), offer.get("payOut"))
|
|
|
570 |
del notReconciled[order[0]]
|
|
|
571 |
print "found match for user", order[1]
|
|
|
572 |
db.shopcluesOrderAffiliateInfo.update({"transactionId":offer.get("transactionId")}, {"$set":{"reconciled":True, "orderId":order[0]}}, multi=True)
|
|
|
573 |
db.merchantOrder.update({"orderId":order[0]}, {"$set":{"reconciled":True, "adId":offer.get("uniqueKey")}}, multi=True)
|
|
|
574 |
break
|
|
|
575 |
|
|
|
576 |
unreconciledOrders = notReconciled.keys()
|
|
|
577 |
|
|
|
578 |
for offer in db.shopcluesOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
579 |
"transactionTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
580 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
581 |
row += 1
|
|
|
582 |
i=-1
|
|
|
583 |
affNotReconciledSheet.write(row, inc(), offer.get("uniqueKey"))
|
|
|
584 |
affNotReconciledSheet.write(row, inc(), offer.get("subTagId"))
|
|
|
585 |
affNotReconciledSheet.write(row, inc(), datetime.strftime(fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
|
|
586 |
affNotReconciledSheet.write(row, inc(), offer.get("transactionValue"))
|
|
|
587 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
|
|
588 |
affNotReconciledSheet.write(row, inc(), offer.get("status"))
|
|
|
589 |
affNotReconciledSheet.write(row, inc(), 'NA')
|
|
|
590 |
|
|
|
591 |
workbook.save(XLS_SC_FILENAME)
|
|
|
592 |
|
| 14647 |
amit.gupta |
593 |
def sendmail(email, message, title, *varargs):
|
| 14450 |
amit.gupta |
594 |
if email == "":
|
|
|
595 |
return
|
|
|
596 |
mailServer = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
|
|
|
597 |
mailServer.ehlo()
|
|
|
598 |
mailServer.starttls()
|
|
|
599 |
mailServer.ehlo()
|
|
|
600 |
|
|
|
601 |
# Create the container (outer) email message.
|
|
|
602 |
msg = MIMEMultipart()
|
|
|
603 |
msg['Subject'] = title
|
|
|
604 |
msg.preamble = title
|
|
|
605 |
html_msg = MIMEText(message, 'html')
|
|
|
606 |
msg.attach(html_msg)
|
|
|
607 |
|
|
|
608 |
#snapdeal more to be added here
|
| 14647 |
amit.gupta |
609 |
for fileName in varargs:
|
|
|
610 |
snapdeal = MIMEBase('application', 'vnd.ms-excel')
|
|
|
611 |
snapdeal.set_payload(file(fileName).read())
|
|
|
612 |
encoders.encode_base64(snapdeal)
|
|
|
613 |
snapdeal.add_header('Content-Disposition', 'attachment;filename=' + fileName)
|
|
|
614 |
msg.attach(snapdeal)
|
| 14450 |
amit.gupta |
615 |
|
|
|
616 |
|
|
|
617 |
email.append('amit.gupta@shop2020.in')
|
|
|
618 |
MAILTO = email
|
|
|
619 |
mailServer.login(SENDER, PASSWORD)
|
|
|
620 |
mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
|
|
|
621 |
|
| 14508 |
amit.gupta |
622 |
def setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet):
|
| 14505 |
amit.gupta |
623 |
boldStyle = xlwt.XFStyle()
|
|
|
624 |
f = xlwt.Font()
|
|
|
625 |
f.bold = True
|
|
|
626 |
boldStyle.font = f
|
| 14501 |
amit.gupta |
627 |
row = 0
|
|
|
628 |
global i
|
|
|
629 |
i=-1
|
|
|
630 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
|
|
631 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
| 14850 |
amit.gupta |
632 |
worksheet.write(row, inc(), 'Username', boldStyle)
|
| 14601 |
amit.gupta |
633 |
worksheet.write(row, inc(), 'Version Code', boldStyle)
|
| 14771 |
amit.gupta |
634 |
worksheet.write(row, inc(), 'Device', boldStyle)
|
| 14501 |
amit.gupta |
635 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
636 |
worksheet.write(row, inc(), 'SubtagId', boldStyle)
|
|
|
637 |
worksheet.write(row, inc(), 'Sale Date', boldStyle)
|
| 14988 |
amit.gupta |
638 |
worksheet.write(row, inc(), 'Dtr Sale Date', boldStyle)
|
| 14501 |
amit.gupta |
639 |
worksheet.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
640 |
worksheet.write(row, inc(), 'Aff Sale Date', boldStyle)
|
|
|
641 |
worksheet.write(row, inc(), 'Aff Sale Amt', boldStyle)
|
|
|
642 |
worksheet.write(row, inc(), 'Aff PayOut', boldStyle)
|
| 14601 |
amit.gupta |
643 |
worksheet.write(row, inc(), 'IP', boldStyle)
|
| 14501 |
amit.gupta |
644 |
worksheet.write(row, inc(), 'Product Title', boldStyle)
|
|
|
645 |
worksheet.write(row, inc(), 'Price', boldStyle)
|
|
|
646 |
worksheet.write(row, inc(), 'Quantity', boldStyle)
|
|
|
647 |
worksheet.write(row, inc(), 'Status', boldStyle)
|
|
|
648 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
649 |
worksheet.write(row, inc(), 'CashBack', boldStyle)
|
|
|
650 |
|
| 14505 |
amit.gupta |
651 |
i = -1
|
| 14501 |
amit.gupta |
652 |
worksheet1.write(row, inc(), 'Order Id', boldStyle)
|
|
|
653 |
worksheet1.write(row, inc(), 'User Id', boldStyle)
|
| 14850 |
amit.gupta |
654 |
worksheet1.write(row, inc(), 'Username', boldStyle)
|
| 14601 |
amit.gupta |
655 |
worksheet1.write(row, inc(), 'Version Code', boldStyle)
|
| 14771 |
amit.gupta |
656 |
worksheet1.write(row, inc(), 'Device', boldStyle)
|
| 14501 |
amit.gupta |
657 |
worksheet1.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
658 |
worksheet1.write(row, inc(), 'SubtagId', boldStyle)
|
|
|
659 |
worksheet1.write(row, inc(), 'Sale Date', boldStyle)
|
| 14988 |
amit.gupta |
660 |
worksheet1.write(row, inc(), 'Dtr Sale Date', boldStyle)
|
| 14501 |
amit.gupta |
661 |
worksheet1.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
662 |
worksheet1.write(row, inc(), 'Aff Sale Date', boldStyle)
|
|
|
663 |
worksheet1.write(row, inc(), 'Aff Sale Amt', boldStyle)
|
|
|
664 |
worksheet1.write(row, inc(), 'Aff PayOut', boldStyle)
|
| 14601 |
amit.gupta |
665 |
worksheet1.write(row, inc(), 'IP', boldStyle)
|
| 14501 |
amit.gupta |
666 |
worksheet1.write(row, inc(), 'Product Title', boldStyle)
|
|
|
667 |
worksheet1.write(row, inc(), 'Price', boldStyle)
|
|
|
668 |
worksheet1.write(row, inc(), 'Quantity', boldStyle)
|
|
|
669 |
worksheet1.write(row, inc(), 'Status', boldStyle)
|
|
|
670 |
worksheet1.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
671 |
worksheet1.write(row, inc(), 'CashBack', boldStyle)
|
| 14508 |
amit.gupta |
672 |
|
|
|
673 |
i = -1
|
|
|
674 |
worksheet2.write(row, inc(), 'Order Id', boldStyle)
|
|
|
675 |
worksheet2.write(row, inc(), 'User Id', boldStyle)
|
| 14850 |
amit.gupta |
676 |
worksheet2.write(row, inc(), 'Username', boldStyle)
|
| 14605 |
amit.gupta |
677 |
worksheet2.write(row, inc(), 'Version Code', boldStyle)
|
| 14771 |
amit.gupta |
678 |
worksheet2.write(row, inc(), 'Device', boldStyle)
|
| 14508 |
amit.gupta |
679 |
worksheet2.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
680 |
worksheet2.write(row, inc(), 'SubtagId', boldStyle)
|
|
|
681 |
worksheet2.write(row, inc(), 'Sale Date', boldStyle)
|
| 14988 |
amit.gupta |
682 |
worksheet2.write(row, inc(), 'Dtr Sale Date', boldStyle)
|
| 14508 |
amit.gupta |
683 |
worksheet2.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
684 |
worksheet2.write(row, inc(), 'Product Title', boldStyle)
|
|
|
685 |
worksheet2.write(row, inc(), 'Price', boldStyle)
|
|
|
686 |
worksheet2.write(row, inc(), 'Quantity', boldStyle)
|
|
|
687 |
worksheet2.write(row, inc(), 'Status', boldStyle)
|
|
|
688 |
worksheet2.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
689 |
worksheet2.write(row, inc(), 'CashBack', boldStyle)
|
| 14450 |
amit.gupta |
690 |
|
| 14508 |
amit.gupta |
691 |
i =-1
|
|
|
692 |
affNotReconciledSheet.write(row, inc(), 'AdId', boldStyle)
|
|
|
693 |
affNotReconciledSheet.write(row, inc(), 'subTagId', boldStyle)
|
|
|
694 |
affNotReconciledSheet.write(row, inc(), 'Sale Date', boldStyle)
|
|
|
695 |
affNotReconciledSheet.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
696 |
affNotReconciledSheet.write(row, inc(), 'Pay Out', boldStyle)
|
|
|
697 |
affNotReconciledSheet.write(row, inc(), 'Status', boldStyle)
|
| 14601 |
amit.gupta |
698 |
affNotReconciledSheet.write(row, inc(), 'IP', boldStyle)
|
| 14524 |
amit.gupta |
699 |
|
|
|
700 |
def getUserAmountReconciled():
|
|
|
701 |
pass
|
|
|
702 |
|
| 14613 |
amit.gupta |
703 |
def getUserOrders():
|
|
|
704 |
global i
|
|
|
705 |
rb = open_workbook(XLS_FILENAME,formatting_info=True)
|
|
|
706 |
wb = copy(rb)
|
|
|
707 |
worksheet = wb.add_sheet("All Users")
|
|
|
708 |
worksheet1 = wb.add_sheet("Suspected Users")
|
| 14632 |
amit.gupta |
709 |
workbook = xlwt.Workbook()
|
|
|
710 |
sh1 = workbook.add_sheet("All Orders")
|
| 15423 |
amit.gupta |
711 |
sh2 = workbook.add_sheet("Flipkart Orders")
|
| 14632 |
amit.gupta |
712 |
|
| 14613 |
amit.gupta |
713 |
db=client.Dtr
|
|
|
714 |
results = Mysql.fetchResult('''
|
| 15932 |
amit.gupta |
715 |
select ow.*, u.username, crm1.order_count, u.referrer, aua.city,aua.state,aua.pincode from order_view ow
|
|
|
716 |
left join users u on u.id = ow.user_id
|
|
|
717 |
left join (select user_id, count(*) as order_count from order_view where status in ('ORDER_CREATED','DETAIL_CREATED') group by user_id)as crm1 on ow.user_id = crm1.user_id
|
|
|
718 |
left join (select * from (select * from all_user_addresses order by source) s group by user_id)aua on aua.user_id=u.id
|
|
|
719 |
where (lower(u.referrer) not like 'emp%' or u.utm_campaign is not null) and u.activated = 1 and ow.status in ('ORDER_CREATED','DETAIL_CREATED');
|
| 14613 |
amit.gupta |
720 |
''',)
|
|
|
721 |
row = 0
|
|
|
722 |
i=-1
|
|
|
723 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
|
|
724 |
worksheet1.write(row, i, 'User Id', boldStyle)
|
|
|
725 |
worksheet.write(row, inc(), 'User name', boldStyle)
|
|
|
726 |
worksheet1.write(row, i, 'User name', boldStyle)
|
|
|
727 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
|
|
728 |
worksheet1.write(row, i, 'Order Id', boldStyle)
|
|
|
729 |
worksheet.write(row, inc(), 'Created On', boldStyle)
|
|
|
730 |
worksheet1.write(row, i, 'Created On', boldStyle)
|
|
|
731 |
worksheet.write(row, inc(), 'Store Id', boldStyle)
|
|
|
732 |
worksheet1.write(row, i, 'Store Id', boldStyle)
|
|
|
733 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
734 |
worksheet1.write(row, i, 'Merchant Order Id', boldStyle)
|
| 14616 |
amit.gupta |
735 |
worksheet.write(row, inc(), 'Product title', boldStyle)
|
|
|
736 |
worksheet1.write(row, i, 'Product title', boldStyle)
|
| 14613 |
amit.gupta |
737 |
worksheet.write(row, inc(), 'Amount Paid', boldStyle)
|
|
|
738 |
worksheet1.write(row, i, 'Amount Paid', boldStyle)
|
|
|
739 |
worksheet.write(row, inc(), 'Cashback', boldStyle)
|
|
|
740 |
worksheet1.write(row, i, 'Cashback', boldStyle)
|
|
|
741 |
worksheet.write(row, inc(), 'Order Status', boldStyle)
|
|
|
742 |
worksheet1.write(row, i, 'Order Status', boldStyle)
|
|
|
743 |
worksheet.write(row, inc(), 'Detailed Status', boldStyle)
|
|
|
744 |
worksheet1.write(row, i, 'Detailed Status', boldStyle)
|
|
|
745 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
746 |
worksheet1.write(row, i, 'Cashback Status', boldStyle)
|
|
|
747 |
worksheet.write(row, inc(), 'Reconciled', boldStyle)
|
|
|
748 |
worksheet1.write(row, i, 'Reconciled', boldStyle)
|
|
|
749 |
worksheet.write(row, inc(), 'IP', boldStyle)
|
|
|
750 |
worksheet1.write(row, i, 'IP', boldStyle)
|
| 14693 |
amit.gupta |
751 |
i=-1
|
|
|
752 |
sh1.write(row, inc(), 'User Id', boldStyle)
|
|
|
753 |
sh1.write(row, inc(), 'User name', boldStyle)
|
|
|
754 |
sh1.write(row, inc(), 'Order Id', boldStyle)
|
|
|
755 |
sh1.write(row, inc(), 'Created On', boldStyle)
|
|
|
756 |
sh1.write(row, inc(), 'Store Id', boldStyle)
|
|
|
757 |
sh1.write(row, inc(), 'Merchant Order Id', boldStyle)
|
| 14771 |
amit.gupta |
758 |
sh1.write(row, inc(), 'Status', boldStyle)
|
| 15932 |
amit.gupta |
759 |
sh1.write(row, inc(), 'Detailed Status', boldStyle)
|
| 14693 |
amit.gupta |
760 |
sh1.write(row, inc(), 'Product title', boldStyle)
|
|
|
761 |
sh1.write(row, inc(), 'Referrer', boldStyle)
|
|
|
762 |
sh1.write(row, inc(), 'Amount Paid', boldStyle)
|
| 14771 |
amit.gupta |
763 |
sh1.write(row, inc(), 'Catalog Id', boldStyle)
|
| 14693 |
amit.gupta |
764 |
sh1.write(row, inc(), 'Brand', boldStyle)
|
|
|
765 |
sh1.write(row, inc(), 'Model', boldStyle)
|
|
|
766 |
sh1.write(row, inc(), 'Category', boldStyle)
|
| 15932 |
amit.gupta |
767 |
sh1.write(row, inc(), 'Deal Rank', boldStyle)
|
|
|
768 |
sh1.write(row, inc(), 'City', boldStyle)
|
|
|
769 |
sh1.write(row, inc(), 'State', boldStyle)
|
|
|
770 |
sh1.write(row, inc(), 'Pincode', boldStyle)
|
| 15423 |
amit.gupta |
771 |
i =-1
|
|
|
772 |
sh2.write(row, inc(), 'User Id', boldStyle)
|
|
|
773 |
sh2.write(row, inc(), 'User name', boldStyle)
|
|
|
774 |
sh2.write(row, inc(), 'Created On', boldStyle)
|
|
|
775 |
sh2.write(row, inc(), 'Store', boldStyle)
|
|
|
776 |
sh2.write(row, inc(), 'Status', boldStyle)
|
|
|
777 |
sh2.write(row, inc(), 'Product title', boldStyle)
|
|
|
778 |
sh2.write(row, inc(), 'Price', boldStyle)
|
|
|
779 |
sh2.write(row, inc(), 'Quantity', boldStyle)
|
|
|
780 |
sh2.write(row, inc(), 'Catalog Id', boldStyle)
|
|
|
781 |
sh2.write(row, inc(), 'Brand', boldStyle)
|
|
|
782 |
sh2.write(row, inc(), 'Model', boldStyle)
|
|
|
783 |
sh2.write(row, inc(), 'Category', boldStyle)
|
| 14613 |
amit.gupta |
784 |
|
|
|
785 |
row=0
|
|
|
786 |
row2=0
|
| 14632 |
amit.gupta |
787 |
row3=0
|
|
|
788 |
db1 = client.Catalog
|
| 14613 |
amit.gupta |
789 |
for result in results:
|
|
|
790 |
morder = db.merchantOrder.find_one({"orderId":result[0]})
|
|
|
791 |
if morder is not None:
|
|
|
792 |
subOrders = morder.get("subOrders")
|
|
|
793 |
if subOrders is not None:
|
|
|
794 |
for subOrder in subOrders:
|
| 14632 |
amit.gupta |
795 |
row3+=1
|
|
|
796 |
i=-1
|
| 14699 |
amit.gupta |
797 |
sh1.write(row3, inc(), result[1])
|
| 15932 |
amit.gupta |
798 |
sh1.write(row3, inc(), result[7])
|
| 14632 |
amit.gupta |
799 |
sh1.write(row3, inc(), result[0])
|
| 15932 |
amit.gupta |
800 |
sh1.write(row3, inc(), result[6], datetime_format)
|
| 14632 |
amit.gupta |
801 |
sh1.write(row3, inc(), sourceMap.get(result[2]))
|
|
|
802 |
sh1.write(row3, inc(), morder.get("merchantOrderId"))
|
| 14771 |
amit.gupta |
803 |
sh1.write(row3, inc(), subOrder.get("status"))
|
| 15932 |
amit.gupta |
804 |
sh1.write(row3, inc(), subOrder.get("detailedStatus"))
|
| 14632 |
amit.gupta |
805 |
sh1.write(row3, inc(), subOrder.get("productTitle"))
|
| 15932 |
amit.gupta |
806 |
sh1.write(row3, inc(), result[9])
|
| 14632 |
amit.gupta |
807 |
inc()
|
|
|
808 |
if int(subOrder.get("quantity")) > 0:
|
|
|
809 |
sh1.write(row3, i, int(subOrder.get("amountPaid"))/int(subOrder.get("quantity")))
|
| 14647 |
amit.gupta |
810 |
skuData = getSkuData(morder.get("storeId"), subOrder.get("productCode"))
|
|
|
811 |
if morder.get("storeId") in (1,2,4,5):
|
|
|
812 |
skuData = db1.MasterData.find_one({'identifier':subOrder.get("productCode").strip(), 'source_id':morder.get("storeId")})
|
|
|
813 |
elif morder.get("storeId") == 3:
|
|
|
814 |
skuData = db1.MasterData.find_one({'secondaryIdentifier':subOrder.get("productCode").strip(), 'source_id':morder.get("storeId")})
|
| 14634 |
amit.gupta |
815 |
if skuData is not None:
|
| 14771 |
amit.gupta |
816 |
sh1.write(row3, inc(), skuData.get("skuBundleId"))
|
| 14634 |
amit.gupta |
817 |
sh1.write(row3, inc(), skuData.get("brand"))
|
|
|
818 |
sh1.write(row3, inc(), skuData.get("model_name"))
|
|
|
819 |
sh1.write(row3, inc(), skuData.get("category"))
|
| 15932 |
amit.gupta |
820 |
sh1.write(row3, inc(), subOrder.get("rank"))
|
|
|
821 |
else:
|
|
|
822 |
sh1.write(row3, inc(), None)
|
|
|
823 |
sh1.write(row3, inc(), None)
|
|
|
824 |
sh1.write(row3, inc(), None)
|
|
|
825 |
sh1.write(row3, inc(), None)
|
|
|
826 |
sh1.write(row3, inc(), None)
|
|
|
827 |
sh1.write(row3, inc(), result[10])
|
|
|
828 |
sh1.write(row3, inc(), result[11])
|
|
|
829 |
sh1.write(row3, inc(), result[12])
|
|
|
830 |
|
| 14881 |
amit.gupta |
831 |
#removed filter as requested by Rajneesh
|
|
|
832 |
#if subOrder.get("cashBackStatus") == Store.CB_APPROVED or subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
|
|
833 |
row +=1
|
|
|
834 |
i=-1
|
|
|
835 |
worksheet.write(row, inc(), result[0])
|
| 15932 |
amit.gupta |
836 |
worksheet.write(row, inc(), result[7])
|
| 14881 |
amit.gupta |
837 |
worksheet.write(row, inc(), result[1])
|
| 15932 |
amit.gupta |
838 |
worksheet.write(row, inc(), result[6], datetime_format)
|
| 14881 |
amit.gupta |
839 |
worksheet.write(row, inc(), result[2])
|
|
|
840 |
worksheet.write(row, inc(), morder.get("merchantOrderId"))
|
|
|
841 |
worksheet.write(row, inc(), subOrder.get("productTitle"))
|
|
|
842 |
worksheet.write(row, inc(), subOrder.get("amountPaid"))
|
|
|
843 |
worksheet.write(row, inc(), subOrder.get("cashBackAmount"))
|
|
|
844 |
worksheet.write(row, inc(), subOrder.get("status"))
|
|
|
845 |
worksheet.write(row, inc(), subOrder.get("detailedStatus"))
|
|
|
846 |
worksheet.write(row, inc(), subOrder.get("cashBackStatus"))
|
|
|
847 |
worksheet.write(row, inc(), False if morder.get("reconciled") is None else True)
|
|
|
848 |
if morder.get("reconciled") and morder.get("storeId")==3:
|
|
|
849 |
try:
|
|
|
850 |
worksheet.write(row, inc(), db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True}).get("ip"))
|
|
|
851 |
except:
|
|
|
852 |
print "Could not find", morder.get("adId"), "that is reconcired for order", morder.get("orderId")
|
| 15932 |
amit.gupta |
853 |
if result[8] >= 10:
|
| 14881 |
amit.gupta |
854 |
row2 +=1
|
| 14613 |
amit.gupta |
855 |
i=-1
|
| 14881 |
amit.gupta |
856 |
worksheet1.write(row2, inc(), result[0])
|
| 15932 |
amit.gupta |
857 |
worksheet1.write(row2, inc(), result[7])
|
| 14881 |
amit.gupta |
858 |
worksheet1.write(row2, inc(), result[1])
|
| 15932 |
amit.gupta |
859 |
worksheet1.write(row2, inc(), result[6], datetime_format)
|
| 14881 |
amit.gupta |
860 |
worksheet1.write(row2, inc(), result[2])
|
|
|
861 |
worksheet1.write(row2, inc(), morder.get("merchantOrderId"))
|
|
|
862 |
worksheet1.write(row2, inc(), subOrder.get("productTitle"))
|
|
|
863 |
worksheet1.write(row2, inc(), subOrder.get("amountPaid"))
|
|
|
864 |
worksheet1.write(row2, inc(), subOrder.get("cashBackAmount"))
|
|
|
865 |
worksheet1.write(row2, inc(), subOrder.get("status"))
|
|
|
866 |
worksheet1.write(row2, inc(), subOrder.get("detailedStatus"))
|
|
|
867 |
worksheet1.write(row2, inc(), subOrder.get("cashBackStatus"))
|
|
|
868 |
worksheet1.write(row2, inc(), False if morder.get("reconciled") is None else True)
|
| 14613 |
amit.gupta |
869 |
if morder.get("reconciled") and morder.get("storeId")==3:
|
|
|
870 |
try:
|
| 14881 |
amit.gupta |
871 |
worksheet1.write(row2, inc(), db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True}).get("ip"))
|
| 14613 |
amit.gupta |
872 |
except:
|
|
|
873 |
print "Could not find", morder.get("adId"), "that is reconcired for order", morder.get("orderId")
|
| 15423 |
amit.gupta |
874 |
|
| 15542 |
amit.gupta |
875 |
flipkartOrders = session.query(FlipkartOrders).order_by(FlipkartOrders.created.desc()).all()
|
| 15540 |
amit.gupta |
876 |
flipkartOrders.reverse()
|
| 15423 |
amit.gupta |
877 |
row3=0
|
| 15430 |
amit.gupta |
878 |
#try:
|
| 15540 |
amit.gupta |
879 |
for order in flipkartOrders:
|
| 15423 |
amit.gupta |
880 |
row3 += 1
|
|
|
881 |
i=-1
|
| 15540 |
amit.gupta |
882 |
sh2.write(row3, inc(), order.user_id)
|
|
|
883 |
sh2.write(row3, inc(), order.email)
|
|
|
884 |
sh2.write(row3, inc(), order.created, datetime_format)
|
| 15423 |
amit.gupta |
885 |
sh2.write(row3, inc(), "Flipkart")
|
| 15540 |
amit.gupta |
886 |
sh2.write(row3, inc(), order.status)
|
|
|
887 |
sh2.write(row3, inc(), order.title)
|
|
|
888 |
sh2.write(row3, inc(), order.price)
|
|
|
889 |
sh2.write(row3, inc(), order.quantity)
|
|
|
890 |
sh2.write(row3, inc(), order.catalogId)
|
|
|
891 |
sh2.write(row3, inc(), order.brand)
|
|
|
892 |
sh2.write(row3, inc(), order.model)
|
|
|
893 |
sh2.write(row3, inc(), order.category)
|
| 14632 |
amit.gupta |
894 |
|
| 14613 |
amit.gupta |
895 |
wb.save(XLS_FILENAME)
|
| 14632 |
amit.gupta |
896 |
workbook.save(XLS_O_FILENAME)
|
| 14647 |
amit.gupta |
897 |
|
|
|
898 |
def getSkuData(storeId, identifier):
|
|
|
899 |
if storeId in (1,2,4,5):
|
|
|
900 |
skuData = client.Catalog.MasterData.find_one({'identifier':identifier, 'source_id':storeId})
|
|
|
901 |
elif storeId == 3:
|
|
|
902 |
skuData = client.Catalog.MasterData.find_one({'secondaryIdentifier':identifier, 'source_id':storeId})
|
|
|
903 |
return skuData
|
|
|
904 |
|
| 14460 |
amit.gupta |
905 |
def inc():
|
|
|
906 |
global i
|
|
|
907 |
i+=1
|
|
|
908 |
return i
|
| 15540 |
amit.gupta |
909 |
|
|
|
910 |
def migrateFlipkartOrders():
|
|
|
911 |
db = client.Dtr
|
|
|
912 |
info = reversed(list(db.flipkartOrderAffiliateInfo.find()))
|
|
|
913 |
#try:
|
|
|
914 |
for order in info:
|
|
|
915 |
userId = None
|
|
|
916 |
subTagId = None
|
|
|
917 |
email = None
|
|
|
918 |
subTagId = order.get("subTagId")
|
|
|
919 |
if subTagId:
|
|
|
920 |
click = session.query(Clicks).filter_by(tag = subTagId).first()
|
|
|
921 |
if click is not None:
|
|
|
922 |
userId= click.user_id
|
|
|
923 |
user = session.query(Users.email).filter_by(id = userId).first()
|
|
|
924 |
if user is not None:
|
|
|
925 |
email = user.email
|
|
|
926 |
|
|
|
927 |
flipkartOrder = FlipkartOrders()
|
|
|
928 |
flipkartOrder.user_id = userId
|
|
|
929 |
flipkartOrder.identifier = order.get("identifier")
|
|
|
930 |
flipkartOrder.email = email
|
|
|
931 |
flipkartOrder.subtagId = order.get("subTagId")
|
|
|
932 |
flipkartOrder.created = datetime.strptime(order.get("saleDate"), "%Y-%m-%d")
|
|
|
933 |
flipkartOrder.status = order.get("conversionStatus")
|
|
|
934 |
flipkartOrder.title = order.get("productTitle")
|
|
|
935 |
flipkartOrder.price = order.get("price")
|
|
|
936 |
flipkartOrder.quantity = order.get("quantity")
|
|
|
937 |
flipkartOrder.productCode = order.get("productCode")
|
|
|
938 |
skuData = getSkuData(2, order.get("productCode"))
|
|
|
939 |
if skuData is not None:
|
|
|
940 |
flipkartOrder.catalogId = skuData.get("skuBundleId")
|
|
|
941 |
flipkartOrder.brand = skuData.get("brand")
|
|
|
942 |
flipkartOrder.model = skuData.get("model_name")
|
|
|
943 |
flipkartOrder.category =categoryMap.get(skuData.get("category_id"))
|
|
|
944 |
flipkartOrder.title =skuData.get("source_product_name")
|
|
|
945 |
|
|
|
946 |
session.commit()
|
| 14632 |
amit.gupta |
947 |
def addHeaders(sheet):
|
|
|
948 |
global i
|
|
|
949 |
i = 0
|
|
|
950 |
sheet.write(0, inc(), )
|
| 14450 |
amit.gupta |
951 |
def main():
|
| 14647 |
amit.gupta |
952 |
|
| 14450 |
amit.gupta |
953 |
generateSnapDealReco()
|
| 14647 |
amit.gupta |
954 |
generateFlipkartReco()
|
| 15791 |
manish.sha |
955 |
generateShopcluesReco()
|
| 14650 |
amit.gupta |
956 |
generateAmazonReco(XLS_A_FILENAME)
|
| 14613 |
amit.gupta |
957 |
getUserOrders()
|
| 15791 |
manish.sha |
958 |
sendmail(["amit.gupta@shop2020.in","rajneesh.arora@saholic.com"], "", "Affiliate Reco", XLS_FILENAME, XLS_F_FILENAME, XLS_A_FILENAME, XLS_SC_FILENAME)
|
| 15578 |
amit.gupta |
959 |
#sendmail(["amit.gupta@shop2020.in"], "", "Affiliate Reco", XLS_FILENAME, XLS_F_FILENAME, XLS_A_FILENAME)
|
| 15541 |
amit.gupta |
960 |
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 |
961 |
|
|
|
962 |
if __name__ == '__main__':
|
| 15440 |
amit.gupta |
963 |
#info = client.Dtr.flipkartOrderAffiliateInfo.find()
|
|
|
964 |
#print info
|
|
|
965 |
main()
|
| 14460 |
amit.gupta |
966 |
|