| 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():
|
|
|
12 |
client = PromotionClient().get_client()
|
|
|
13 |
dayExpiry = []
|
|
|
14 |
expired = []
|
|
|
15 |
promotionIds = [16,18,26,27,33]
|
|
|
16 |
for promotionId in promotionIds:
|
|
|
17 |
coupons = client.getAllCouponsByPromotionId(promotionId)
|
|
|
18 |
for coupon in coupons:
|
|
|
19 |
endTime = None
|
|
|
20 |
args = eval(coupon.arguments)
|
|
|
21 |
if args:
|
|
|
22 |
if 'end_on' in args:
|
|
|
23 |
endTime = datetime.datetime.strptime(args['end_on'], '%Y-%m-%d')
|
|
|
24 |
elif 'endOn' in args:
|
|
|
25 |
endTime = datetime.datetime.fromtimestamp(args['endOn']/1000)
|
|
|
26 |
else:
|
|
|
27 |
continue
|
|
|
28 |
curTime = datetime.datetime.now()
|
|
|
29 |
diff = endTime - curTime
|
|
|
30 |
hoursDiff = diff.seconds/3600
|
|
|
31 |
daysDiff = diff.days
|
|
|
32 |
if daysDiff == 0:
|
|
|
33 |
dayExpiry.append("<b>" + coupon.couponCode + "(" + coupon.promotion.name + ")</b> will expire in " + str(hoursDiff) + " hours")
|
|
|
34 |
elif daysDiff == 1:
|
|
|
35 |
dayExpiry.append("<b>" + coupon.couponCode + "(" + coupon.promotion.name + ")</b> will expire in " + str(24 + hoursDiff) + " hours")
|
|
|
36 |
elif daysDiff == -1:
|
|
|
37 |
expired.append("<b>" + coupon.couponCode + "(" + coupon.promotion.name + ")</b> has been expired " + str(24 - hoursDiff) + " hours ago")
|
|
|
38 |
|
| 7233 |
amit.gupta |
39 |
message = ""
|
| 7008 |
amit.gupta |
40 |
if (dayExpiry or expired):
|
|
|
41 |
if dayExpiry:
|
| 7233 |
amit.gupta |
42 |
message += "<br>".join(dayExpiry) + "<br><br>"
|
| 7008 |
amit.gupta |
43 |
|
|
|
44 |
if expired:
|
|
|
45 |
message += "<br>".join(expired)
|
|
|
46 |
|
|
|
47 |
message += "<br><br>Please take appropriate action if required"
|
|
|
48 |
|
|
|
49 |
__send_mail(message)
|
|
|
50 |
|
|
|
51 |
def main():
|
|
|
52 |
notify()
|
|
|
53 |
|
|
|
54 |
def __send_mail(message):
|
|
|
55 |
try:
|
| 7379 |
amit.gupta |
56 |
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"], 'Coupons Expiry Alert', message))
|
| 7008 |
amit.gupta |
57 |
thread.start()
|
|
|
58 |
except Exception as ex:
|
|
|
59 |
print ex
|
|
|
60 |
|
|
|
61 |
if __name__ == '__main__':
|
|
|
62 |
main()
|