| 14772 |
kshitij.so |
1 |
'''
|
|
|
2 |
Created on Mar 10, 2015
|
|
|
3 |
|
|
|
4 |
'''
|
|
|
5 |
from datetime import date, datetime, timedelta
|
|
|
6 |
from dtr.storage.Mysql import getOrdersAfterDate, \
|
|
|
7 |
getOrdersByTag
|
|
|
8 |
from email import encoders
|
|
|
9 |
from email.mime.base import MIMEBase
|
|
|
10 |
from email.mime.multipart import MIMEMultipart
|
|
|
11 |
from email.mime.text import MIMEText
|
|
|
12 |
from pymongo.mongo_client import MongoClient
|
|
|
13 |
from xlrd import open_workbook
|
|
|
14 |
from xlutils.copy import copy
|
|
|
15 |
from xlwt.Workbook import Workbook
|
|
|
16 |
import MySQLdb
|
|
|
17 |
import smtplib
|
|
|
18 |
import time
|
|
|
19 |
import xlwt
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
DB_HOST = "localhost"
|
|
|
24 |
DB_USER = "root"
|
|
|
25 |
DB_PASSWORD = "shop2020"
|
|
|
26 |
DB_NAME = "dtr"
|
|
|
27 |
TMP_FILE = "User_Activity_Report.xls"
|
|
|
28 |
|
|
|
29 |
# KEY NAMES
|
|
|
30 |
SENDER = "cnc.center@shop2020.in"
|
|
|
31 |
PASSWORD = "5h0p2o2o"
|
|
|
32 |
SUBJECT = "User Activity Report for" + date.today().isoformat()
|
|
|
33 |
SMTP_SERVER = "smtp.gmail.com"
|
|
|
34 |
SMTP_PORT = 587
|
|
|
35 |
|
|
|
36 |
DATE_QUERY="""
|
|
|
37 |
SELECT date(d.visited) from daily_visitors d
|
| 14871 |
manas |
38 |
join users u where u.id=d.user_id AND LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
39 |
AND date(d.visited) > '2015-03-08' group by visited ;
|
|
|
40 |
"""
|
|
|
41 |
|
|
|
42 |
MONTH_QUERY="""
|
|
|
43 |
SELECT month(d.visited) from daily_visitors d
|
| 14871 |
manas |
44 |
join users u on u.id=d.user_id where LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
45 |
group by month(d.visited);
|
|
|
46 |
"""
|
|
|
47 |
|
|
|
48 |
WEEK_QUERY="""
|
|
|
49 |
SELECT CONCAT(date(o.created), ' - ', date(o.created) + INTERVAL 6 DAY) AS week
|
|
|
50 |
FROM order_view o
|
|
|
51 |
JOIN users u ON u.id = o.user_id
|
| 14871 |
manas |
52 |
WHERE LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
53 |
AND date(o.created) > '2015-03-08'
|
|
|
54 |
GROUP BY WEEK(date(o.created))
|
|
|
55 |
ORDER BY WEEK(date(o.created))
|
|
|
56 |
"""
|
|
|
57 |
|
|
|
58 |
DNRU_QUERY="""
|
|
|
59 |
SELECT count(*)
|
| 14871 |
manas |
60 |
FROM users u WHERE LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
61 |
AND date(u.created) > '2015-03-08'
|
|
|
62 |
group by date(u.created)
|
|
|
63 |
order by date(u.created)
|
|
|
64 |
"""
|
|
|
65 |
|
|
|
66 |
DAU_QUERY="""
|
|
|
67 |
SELECT count(distinct d.user_id)
|
| 14871 |
manas |
68 |
FROM daily_visitors d join users u where u.id=d.user_id AND LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
69 |
AND date(d.visited) > '2015-03-08' group by visited ;
|
|
|
70 |
"""
|
|
|
71 |
|
|
|
72 |
DAB_QUERY="""
|
|
|
73 |
SELECT COUNT(DISTINCT o.user_id )
|
|
|
74 |
FROM order_view o
|
|
|
75 |
JOIN users u ON u.id = o.user_id
|
| 14871 |
manas |
76 |
WHERE LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
77 |
AND o.STATUS = 'ORDER_CREATED'
|
|
|
78 |
AND date(o.created) > '2015-03-08'
|
|
|
79 |
group by date(o.created)
|
|
|
80 |
order by date(o.created)
|
|
|
81 |
"""
|
|
|
82 |
|
|
|
83 |
DTO_QUERY="""
|
|
|
84 |
SELECT COUNT( *)
|
|
|
85 |
FROM order_view o
|
|
|
86 |
JOIN users u ON u.id = o.user_id
|
| 14871 |
manas |
87 |
WHERE LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
88 |
AND o.STATUS = 'ORDER_CREATED'
|
|
|
89 |
AND date(o.created) > '2015-03-08'
|
|
|
90 |
GROUP BY DATE(o.created)
|
|
|
91 |
order by date(o.created)
|
|
|
92 |
"""
|
|
|
93 |
|
|
|
94 |
MNRU_QUERY="""
|
|
|
95 |
SELECT count(*)
|
| 14871 |
manas |
96 |
FROM users u WHERE LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
97 |
AND date(u.created) > '2015-03-08'
|
|
|
98 |
group by month(u.created)
|
|
|
99 |
order by month(u.created)
|
|
|
100 |
"""
|
|
|
101 |
|
|
|
102 |
MAU_QUERY="""
|
|
|
103 |
SELECT count(distinct d.user_id)
|
| 14871 |
manas |
104 |
FROM daily_visitors d join users u where u.id=d.user_id AND LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
105 |
AND date(d.visited) > '2015-03-08'
|
|
|
106 |
group by month(d.visited)
|
|
|
107 |
order by month(d.visited);
|
|
|
108 |
"""
|
|
|
109 |
|
|
|
110 |
MAB_QUERY="""
|
|
|
111 |
SELECT COUNT(DISTINCT o.user_id )
|
|
|
112 |
FROM order_view o
|
|
|
113 |
JOIN users u ON u.id = o.user_id where
|
| 14871 |
manas |
114 |
LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
115 |
AND o.STATUS = 'ORDER_CREATED'
|
|
|
116 |
AND date(o.created) > '2015-03-08'
|
|
|
117 |
group by month(o.created)
|
|
|
118 |
order by month(o.created);
|
|
|
119 |
"""
|
|
|
120 |
|
|
|
121 |
MTO_QUERY="""
|
|
|
122 |
SELECT COUNT( *)
|
|
|
123 |
FROM order_view o
|
|
|
124 |
JOIN users u ON u.id = o.user_id where
|
| 14871 |
manas |
125 |
LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
126 |
AND o.STATUS = 'ORDER_CREATED'
|
|
|
127 |
AND date(o.created) > '2015-03-08'
|
|
|
128 |
GROUP BY MONTH(o.created)
|
|
|
129 |
order by month(o.created);
|
|
|
130 |
"""
|
|
|
131 |
|
|
|
132 |
WNRU_QUERY="""
|
|
|
133 |
SELECT COUNT(*)
|
|
|
134 |
FROM users u WHERE
|
| 14871 |
manas |
135 |
LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
136 |
AND date(u.created) > '2015-03-08'
|
|
|
137 |
GROUP BY WEEK(date(u.created))
|
|
|
138 |
ORDER BY WEEK(date(u.created))
|
|
|
139 |
|
|
|
140 |
"""
|
|
|
141 |
WAU_QUERY="""
|
|
|
142 |
SELECT COUNT(distinct d.user_id) AS total
|
| 14871 |
manas |
143 |
FROM daily_visitors d join users u where u.id=d.user_id AND LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
144 |
AND date(d.visited) > '2015-03-08'
|
|
|
145 |
GROUP BY WEEK(d.visited)
|
|
|
146 |
ORDER BY WEEK(d.visited)
|
|
|
147 |
"""
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
WAB_QUERY="""
|
|
|
151 |
SELECT COUNT( DISTINCT o.user_id )
|
|
|
152 |
FROM order_view o
|
|
|
153 |
JOIN users u ON u.id = o.user_id
|
| 14871 |
manas |
154 |
WHERE LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
155 |
AND o.STATUS = 'ORDER_CREATED'
|
|
|
156 |
AND date(o.created) > '2015-03-08'
|
|
|
157 |
GROUP BY WEEK(date(o.created))
|
|
|
158 |
ORDER BY WEEK(date(o.created))
|
|
|
159 |
"""
|
|
|
160 |
|
|
|
161 |
WTO_QUERY="""
|
|
|
162 |
SELECT COUNT(*)
|
|
|
163 |
FROM order_view o
|
|
|
164 |
JOIN users u ON u.id = o.user_id
|
| 14871 |
manas |
165 |
WHERE LOWER(u.referrer) NOT LIKE 'emp%' AND u.activated =1
|
| 14772 |
kshitij.so |
166 |
AND o.STATUS = 'ORDER_CREATED'
|
|
|
167 |
AND date(o.created) > '2015-03-08'
|
|
|
168 |
GROUP BY WEEK(date(o.created))
|
|
|
169 |
ORDER BY WEEK(date(o.created))
|
|
|
170 |
"""
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
date_format = xlwt.XFStyle()
|
|
|
174 |
date_format.num_format_str = 'yyyy/mm/dd'
|
|
|
175 |
|
|
|
176 |
datetime_format = xlwt.XFStyle()
|
|
|
177 |
datetime_format.num_format_str = 'yyyy/mm/dd HH:MM AM/PM'
|
|
|
178 |
|
|
|
179 |
default_format = xlwt.XFStyle()
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
def getDbConnection():
|
|
|
183 |
return MySQLdb.connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
def generateDailyReport():
|
|
|
187 |
datesql= DATE_QUERY
|
|
|
188 |
dnruSql = DNRU_QUERY
|
|
|
189 |
dauSql = DAU_QUERY
|
|
|
190 |
dabSql = DAB_QUERY
|
|
|
191 |
dtoSql = DTO_QUERY
|
|
|
192 |
conn = getDbConnection()
|
|
|
193 |
|
|
|
194 |
# prepare a cursor object using cursor() method
|
|
|
195 |
cursor = conn.cursor()
|
|
|
196 |
# Execute the SQL command
|
|
|
197 |
# Fetch source id.
|
|
|
198 |
cursor.execute(datesql)
|
|
|
199 |
result = cursor.fetchall()
|
|
|
200 |
global workbook
|
|
|
201 |
workbook = xlwt.Workbook()
|
|
|
202 |
worksheet = workbook.add_sheet("User")
|
|
|
203 |
boldStyle = xlwt.XFStyle()
|
|
|
204 |
f = xlwt.Font()
|
|
|
205 |
f.bold = True
|
|
|
206 |
boldStyle.font = f
|
|
|
207 |
column = 0
|
|
|
208 |
row = 0
|
|
|
209 |
sumdata=17
|
|
|
210 |
worksheet.write(row, 0, 'Date', boldStyle)
|
|
|
211 |
worksheet.write(row, 1, 'TRU', boldStyle)
|
|
|
212 |
worksheet.write(row, 2, 'NRU', boldStyle)
|
|
|
213 |
worksheet.write(row, 3, 'DAU', boldStyle)
|
|
|
214 |
worksheet.write(row, 4, 'DAB', boldStyle)
|
|
|
215 |
worksheet.write(row, 5, 'DTO', boldStyle)
|
|
|
216 |
|
|
|
217 |
for r in result:
|
|
|
218 |
row += 1
|
|
|
219 |
column = 0
|
|
|
220 |
for data in r :
|
|
|
221 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
222 |
column += 1
|
|
|
223 |
|
|
|
224 |
row = 0
|
|
|
225 |
cursor.execute(dnruSql)
|
|
|
226 |
result = cursor.fetchall()
|
|
|
227 |
for r in result:
|
|
|
228 |
row += 1
|
|
|
229 |
column = 1
|
|
|
230 |
for data in r :
|
|
|
231 |
print "Data" + str(data)
|
|
|
232 |
sumdata=sumdata+data
|
|
|
233 |
print "Sum Data" + str(sumdata)
|
|
|
234 |
worksheet.write(row, column, int(sumdata) if type(sumdata) is float else sumdata, date_format if type(sumdata) is date else default_format)
|
|
|
235 |
column += 1
|
|
|
236 |
|
|
|
237 |
row = 0
|
|
|
238 |
cursor.execute(dnruSql)
|
|
|
239 |
result = cursor.fetchall()
|
|
|
240 |
for r in result:
|
|
|
241 |
row += 1
|
|
|
242 |
column = 2
|
|
|
243 |
for data in r :
|
|
|
244 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
245 |
column += 1
|
|
|
246 |
|
|
|
247 |
row = 0
|
|
|
248 |
cursor.execute(dauSql)
|
|
|
249 |
result = cursor.fetchall()
|
|
|
250 |
|
|
|
251 |
for r in result:
|
|
|
252 |
row += 1
|
|
|
253 |
column = 3
|
|
|
254 |
for data in r :
|
|
|
255 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
256 |
column += 1
|
|
|
257 |
|
|
|
258 |
row = 0
|
|
|
259 |
cursor.execute(dabSql)
|
|
|
260 |
result = cursor.fetchall()
|
|
|
261 |
|
|
|
262 |
for r in result:
|
|
|
263 |
row += 1
|
|
|
264 |
column = 4
|
|
|
265 |
for data in r :
|
|
|
266 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
267 |
column += 1
|
|
|
268 |
|
|
|
269 |
row = 0
|
|
|
270 |
cursor.execute(dtoSql)
|
|
|
271 |
result = cursor.fetchall()
|
|
|
272 |
|
|
|
273 |
for r in result:
|
|
|
274 |
row += 1
|
|
|
275 |
column = 5
|
|
|
276 |
for data in r :
|
|
|
277 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
278 |
column += 1
|
|
|
279 |
|
|
|
280 |
|
|
|
281 |
def generateMonthlyReport():
|
|
|
282 |
monthSql = MONTH_QUERY
|
|
|
283 |
mnruSql = MNRU_QUERY
|
|
|
284 |
mauSql = MAU_QUERY
|
|
|
285 |
mabSql = MAB_QUERY
|
|
|
286 |
mtoSql = MTO_QUERY
|
|
|
287 |
|
|
|
288 |
conn = getDbConnection()
|
|
|
289 |
|
|
|
290 |
cursor = conn.cursor()
|
|
|
291 |
|
|
|
292 |
cursor.execute(monthSql)
|
|
|
293 |
result = cursor.fetchall()
|
|
|
294 |
rb = open_workbook(TMP_FILE)
|
|
|
295 |
wb = copy(rb)
|
|
|
296 |
worksheet = workbook.add_sheet("Monthly")
|
|
|
297 |
boldStyle = xlwt.XFStyle()
|
|
|
298 |
f = xlwt.Font()
|
|
|
299 |
f.bold = True
|
|
|
300 |
boldStyle.font = f
|
|
|
301 |
column = 0
|
|
|
302 |
row = 0
|
|
|
303 |
sumdata=17
|
|
|
304 |
worksheet.write(row, 0, 'Month', boldStyle)
|
|
|
305 |
worksheet.write(row, 1, 'MTRU', boldStyle)
|
|
|
306 |
worksheet.write(row, 2, 'MNRU', boldStyle)
|
|
|
307 |
worksheet.write(row, 3, 'MAU', boldStyle)
|
|
|
308 |
worksheet.write(row, 4, 'MAB', boldStyle)
|
|
|
309 |
worksheet.write(row, 5, 'MTO', boldStyle)
|
|
|
310 |
|
|
|
311 |
|
|
|
312 |
for r in result:
|
|
|
313 |
row += 1
|
|
|
314 |
column = 0
|
|
|
315 |
for data in r :
|
|
|
316 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
317 |
column += 1
|
|
|
318 |
|
|
|
319 |
row = 0
|
|
|
320 |
cursor.execute(mnruSql)
|
|
|
321 |
result = cursor.fetchall()
|
|
|
322 |
for r in result:
|
|
|
323 |
row += 1
|
|
|
324 |
column = 1
|
|
|
325 |
for data in r :
|
|
|
326 |
print "Data" + str(data)
|
|
|
327 |
sumdata=sumdata+data
|
|
|
328 |
print "Sum Data" + str(sumdata)
|
|
|
329 |
worksheet.write(row, column, int(sumdata) if type(sumdata) is float else sumdata, date_format if type(sumdata) is date else default_format)
|
|
|
330 |
column += 1
|
|
|
331 |
|
|
|
332 |
row = 0
|
|
|
333 |
cursor.execute(mnruSql)
|
|
|
334 |
result = cursor.fetchall()
|
|
|
335 |
for r in result:
|
|
|
336 |
row += 1
|
|
|
337 |
column = 2
|
|
|
338 |
for data in r :
|
|
|
339 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
340 |
column += 1
|
|
|
341 |
|
|
|
342 |
row = 0
|
|
|
343 |
cursor.execute(mauSql)
|
|
|
344 |
result = cursor.fetchall()
|
|
|
345 |
|
|
|
346 |
for r in result:
|
|
|
347 |
row += 1
|
|
|
348 |
column = 3
|
|
|
349 |
for data in r :
|
|
|
350 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
351 |
column += 1
|
|
|
352 |
|
|
|
353 |
row = 0
|
|
|
354 |
cursor.execute(mabSql)
|
|
|
355 |
result = cursor.fetchall()
|
|
|
356 |
|
|
|
357 |
for r in result:
|
|
|
358 |
row += 1
|
|
|
359 |
column = 4
|
|
|
360 |
for data in r :
|
|
|
361 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
362 |
column += 1
|
|
|
363 |
|
|
|
364 |
row = 0
|
|
|
365 |
cursor.execute(mtoSql)
|
|
|
366 |
result = cursor.fetchall()
|
|
|
367 |
|
|
|
368 |
for r in result:
|
|
|
369 |
row += 1
|
|
|
370 |
column = 5
|
|
|
371 |
for data in r :
|
|
|
372 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
373 |
column += 1
|
|
|
374 |
|
|
|
375 |
workbook.save(TMP_FILE)
|
| 14805 |
kshitij.so |
376 |
sendmail(["manas.kapoor@shop2020.in","rajneesh.arora@saholic.com"], "", TMP_FILE, SUBJECT)
|
| 14772 |
kshitij.so |
377 |
|
|
|
378 |
|
|
|
379 |
def generateWeeklyReport():
|
|
|
380 |
weekSql = WEEK_QUERY
|
|
|
381 |
wnruSql = WNRU_QUERY
|
|
|
382 |
wauSql = WAU_QUERY
|
|
|
383 |
wabSql = WAB_QUERY
|
|
|
384 |
wtoSql = WTO_QUERY
|
|
|
385 |
|
|
|
386 |
conn = getDbConnection()
|
|
|
387 |
|
|
|
388 |
cursor = conn.cursor()
|
|
|
389 |
|
|
|
390 |
cursor.execute(weekSql)
|
|
|
391 |
result = cursor.fetchall()
|
|
|
392 |
rb = open_workbook(TMP_FILE)
|
|
|
393 |
wb = copy(rb)
|
|
|
394 |
worksheet = workbook.add_sheet("Weekly")
|
|
|
395 |
boldStyle = xlwt.XFStyle()
|
|
|
396 |
f = xlwt.Font()
|
|
|
397 |
f.bold = True
|
|
|
398 |
boldStyle.font = f
|
|
|
399 |
column = 0
|
|
|
400 |
row = 0
|
|
|
401 |
sumdata=17
|
|
|
402 |
worksheet.write(row, 0, 'Week', boldStyle)
|
|
|
403 |
worksheet.write(row, 1, 'WTRU', boldStyle)
|
|
|
404 |
worksheet.write(row, 2, 'WNRU', boldStyle)
|
|
|
405 |
worksheet.write(row, 3, 'WAU', boldStyle)
|
|
|
406 |
worksheet.write(row, 4, 'WAB', boldStyle)
|
|
|
407 |
worksheet.write(row, 5, 'WTO', boldStyle)
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
for r in result:
|
|
|
411 |
row += 1
|
|
|
412 |
column = 0
|
|
|
413 |
for data in r :
|
|
|
414 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
415 |
column += 1
|
|
|
416 |
|
|
|
417 |
row = 0
|
|
|
418 |
cursor.execute(wnruSql)
|
|
|
419 |
result = cursor.fetchall()
|
|
|
420 |
for r in result:
|
|
|
421 |
row += 1
|
|
|
422 |
column = 1
|
|
|
423 |
for data in r :
|
|
|
424 |
print "Data" + str(data)
|
|
|
425 |
sumdata=sumdata+data
|
|
|
426 |
print "Sum Data" + str(sumdata)
|
|
|
427 |
worksheet.write(row, column, int(sumdata) if type(sumdata) is float else sumdata, date_format if type(sumdata) is date else default_format)
|
|
|
428 |
column += 1
|
|
|
429 |
|
|
|
430 |
row = 0
|
|
|
431 |
cursor.execute(wnruSql)
|
|
|
432 |
result = cursor.fetchall()
|
|
|
433 |
for r in result:
|
|
|
434 |
row += 1
|
|
|
435 |
column = 2
|
|
|
436 |
for data in r :
|
|
|
437 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
438 |
column += 1
|
|
|
439 |
|
|
|
440 |
row = 0
|
|
|
441 |
cursor.execute(wauSql)
|
|
|
442 |
result = cursor.fetchall()
|
|
|
443 |
|
|
|
444 |
for r in result:
|
|
|
445 |
row += 1
|
|
|
446 |
column = 3
|
|
|
447 |
for data in r :
|
|
|
448 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
449 |
column += 1
|
|
|
450 |
|
|
|
451 |
row = 0
|
|
|
452 |
cursor.execute(wabSql)
|
|
|
453 |
result = cursor.fetchall()
|
|
|
454 |
|
|
|
455 |
for r in result:
|
|
|
456 |
row += 1
|
|
|
457 |
column = 4
|
|
|
458 |
for data in r :
|
|
|
459 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
460 |
column += 1
|
|
|
461 |
|
|
|
462 |
row = 0
|
|
|
463 |
cursor.execute(wtoSql)
|
|
|
464 |
result = cursor.fetchall()
|
|
|
465 |
|
|
|
466 |
for r in result:
|
|
|
467 |
row += 1
|
|
|
468 |
column = 5
|
|
|
469 |
for data in r :
|
|
|
470 |
worksheet.write(row, column, int(data) if type(data) is float else data, date_format if type(data) is date else default_format)
|
|
|
471 |
column += 1
|
|
|
472 |
|
|
|
473 |
|
|
|
474 |
def sendmail(email, message, fileName, title):
|
|
|
475 |
if email == "":
|
|
|
476 |
return
|
|
|
477 |
mailServer = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
|
|
|
478 |
mailServer.ehlo()
|
|
|
479 |
mailServer.starttls()
|
|
|
480 |
mailServer.ehlo()
|
|
|
481 |
|
|
|
482 |
# Create the container (outer) email message.
|
|
|
483 |
msg = MIMEMultipart()
|
|
|
484 |
msg['Subject'] = title
|
|
|
485 |
msg.preamble = title
|
|
|
486 |
html_msg = MIMEText(message, 'html')
|
|
|
487 |
msg.attach(html_msg)
|
|
|
488 |
|
|
|
489 |
fileMsg = MIMEBase('application', 'vnd.ms-excel')
|
|
|
490 |
fileMsg.set_payload(file(TMP_FILE).read())
|
|
|
491 |
encoders.encode_base64(fileMsg)
|
|
|
492 |
fileMsg.add_header('Content-Disposition', 'attachment;filename=' + fileName)
|
|
|
493 |
msg.attach(fileMsg)
|
| 14805 |
kshitij.so |
494 |
|
|
|
495 |
MAILTO = ['manas.kapoor@saholic.com','rajneesh.arora@saholic.com']
|
| 14772 |
kshitij.so |
496 |
mailServer.login(SENDER, PASSWORD)
|
|
|
497 |
mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
|
|
|
498 |
|
|
|
499 |
def main():
|
|
|
500 |
#date = raw_input('Enter a date name: ')
|
|
|
501 |
generateDailyReport()
|
|
|
502 |
generateWeeklyReport()
|
|
|
503 |
generateMonthlyReport()
|
|
|
504 |
|
|
|
505 |
if __name__ == '__main__':
|
|
|
506 |
main()
|
|
|
507 |
|
|
|
508 |
|