Rev 7234 | Rev 7746 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/pythonfrom functools import partialfrom shop2020.clients.PromotionClient import PromotionClientfrom shop2020.utils.EmailAttachmentSender import mail, mail_htmlimport datetimeimport osimport sysimport threadingdef notify():client = PromotionClient().get_client()dayExpiry = []expired = []promotionIds = [16,18,26,27,33]for promotionId in promotionIds:coupons = client.getAllCouponsByPromotionId(promotionId)for coupon in coupons:endTime = Noneargs = eval(coupon.arguments)if args:if 'end_on' in args:endTime = datetime.datetime.strptime(args['end_on'], '%Y-%m-%d')elif 'endOn' in args:endTime = datetime.datetime.fromtimestamp(args['endOn']/1000)else:continuecurTime = datetime.datetime.now()diff = endTime - curTimehoursDiff = diff.seconds/3600daysDiff = diff.daysif daysDiff == 0:dayExpiry.append("<b>" + coupon.couponCode + "(" + coupon.promotion.name + ")</b> will expire in " + str(hoursDiff) + " hours")elif daysDiff == 1:dayExpiry.append("<b>" + coupon.couponCode + "(" + coupon.promotion.name + ")</b> will expire in " + str(24 + hoursDiff) + " hours")elif daysDiff == -1:expired.append("<b>" + coupon.couponCode + "(" + coupon.promotion.name + ")</b> has been expired " + str(24 - hoursDiff) + " hours ago")message = ""if (dayExpiry or expired):if dayExpiry:message += "<br>".join(dayExpiry) + "<br><br>"if expired:message += "<br>".join(expired)message += "<br><br>Please take appropriate action if required"__send_mail(message)def main():notify()def __send_mail(message):try: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))thread.start()except Exception as ex:print exif __name__ == '__main__':main()