| 7008 |
amit.gupta |
1 |
#!/usr/bin/python
|
|
|
2 |
from functools import partial
|
|
|
3 |
from shop2020.clients.PromotionClient import PromotionClient
|
|
|
4 |
from shop2020.utils.EmailAttachmentSender import mail, mail_html
|
|
|
5 |
import datetime
|
|
|
6 |
import os
|
|
|
7 |
import sys
|
|
|
8 |
import threading
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
def notify():
|
| 7746 |
amit.gupta |
12 |
message = ""
|
|
|
13 |
curTime = datetime.datetime.now()
|
| 7008 |
amit.gupta |
14 |
client = PromotionClient().get_client()
|
|
|
15 |
dayExpiry = []
|
|
|
16 |
expired = []
|
| 7746 |
amit.gupta |
17 |
allPromotions = client.getAllPromotions()
|
|
|
18 |
for promotion in allPromotions:
|
|
|
19 |
endOn = datetime.datetime.fromtimestamp(promotion.endOn/1000)
|
|
|
20 |
diff1 = curTime-endOn
|
|
|
21 |
if diff1.days >= 15:
|
|
|
22 |
if client.removeAllCouponsByPromotionId(promotion.id) > 0:
|
|
|
23 |
message += "<br>All coupons related to promotion id <b>" +`promotion.id` + "(" + promotion.name + ")</b> have been deleted. <br>This promotion was expired on <b>" + str(endOn) + "</b>.<br>"
|
| 7008 |
amit.gupta |
24 |
promotionIds = [16,18,26,27,33]
|
|
|
25 |
for promotionId in promotionIds:
|
|
|
26 |
coupons = client.getAllCouponsByPromotionId(promotionId)
|
|
|
27 |
for coupon in coupons:
|
|
|
28 |
endTime = None
|
|
|
29 |
args = eval(coupon.arguments)
|
|
|
30 |
if args:
|
|
|
31 |
if 'end_on' in args:
|
|
|
32 |
endTime = datetime.datetime.strptime(args['end_on'], '%Y-%m-%d')
|
|
|
33 |
elif 'endOn' in args:
|
|
|
34 |
endTime = datetime.datetime.fromtimestamp(args['endOn']/1000)
|
|
|
35 |
else:
|
|
|
36 |
continue
|
|
|
37 |
diff = endTime - curTime
|
|
|
38 |
hoursDiff = diff.seconds/3600
|
|
|
39 |
daysDiff = diff.days
|
|
|
40 |
if daysDiff == 0:
|
|
|
41 |
dayExpiry.append("<b>" + coupon.couponCode + "(" + coupon.promotion.name + ")</b> will expire in " + str(hoursDiff) + " hours")
|
|
|
42 |
elif daysDiff == 1:
|
|
|
43 |
dayExpiry.append("<b>" + coupon.couponCode + "(" + coupon.promotion.name + ")</b> will expire in " + str(24 + hoursDiff) + " hours")
|
|
|
44 |
elif daysDiff == -1:
|
|
|
45 |
expired.append("<b>" + coupon.couponCode + "(" + coupon.promotion.name + ")</b> has been expired " + str(24 - hoursDiff) + " hours ago")
|
|
|
46 |
|
|
|
47 |
if (dayExpiry or expired):
|
|
|
48 |
if dayExpiry:
|
| 7233 |
amit.gupta |
49 |
message += "<br>".join(dayExpiry) + "<br><br>"
|
| 7008 |
amit.gupta |
50 |
|
|
|
51 |
if expired:
|
|
|
52 |
message += "<br>".join(expired)
|
|
|
53 |
|
|
|
54 |
message += "<br><br>Please take appropriate action if required"
|
|
|
55 |
|
| 7746 |
amit.gupta |
56 |
if message != '':
|
|
|
57 |
print message
|
| 7008 |
amit.gupta |
58 |
__send_mail(message)
|
|
|
59 |
|
|
|
60 |
def main():
|
|
|
61 |
notify()
|
|
|
62 |
|
|
|
63 |
def __send_mail(message):
|
|
|
64 |
try:
|
| 10687 |
rajveer |
65 |
thread = threading.Thread(target=partial(mail_html, "cnc.center@shop2020.in", "5h0p2o2o", ["pramit.singh@shop2020.in", "khushal.bhatia@shop2020.in", "chandan.kumar@shop2020.in", "chaitnaya.vats@shop2020.in", "rajneesh.arora@shop2020.in", "amit.sirohi@shop2020.in","manoj.kumar@shop2020.in"], 'Coupons Expiry Alert', message))
|
| 7008 |
amit.gupta |
66 |
thread.start()
|
|
|
67 |
except Exception as ex:
|
|
|
68 |
print ex
|
|
|
69 |
|
|
|
70 |
if __name__ == '__main__':
|
| 10687 |
rajveer |
71 |
main()
|