Subversion Repositories SmartDukaan

Rev

Rev 7379 | Rev 7757 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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