def _send_email(): sq = Sql() # items_alert = {column_id, item_id, user_price, item_price, name, email} items_alert = sq.check_item_need_to_remind() logging.warning('This loop sent email: %s', items_alert) for item_alert in items_alert: # item: [email, item_name, item_price, user_price, item_id, column_id] item_url = 'https://item.jd.com/' + str(item_alert['item_id']) + '.html' email_text = ' 您监控的物品:' + item_alert['name'] + ',现在价格为:' + item_alert['item_price'] + \ ',您设定的价格为:' + item_alert['user_price'] + ',赶紧购买吧!' + item_url email_subject = '您监控的物品降价了!' try: send_email = Mail(email_text, '价格监控系统', '亲爱的用户', email_subject, item_alert['email']) send_email.send() time.sleep(Email_TIME) except: logging.critical('Sent email failure, skip in this loop: %s', item_alert['email']) continue sq.update_status(item_alert['column_id']) logging.warning('Sent monitor email SUCCESS: %s', item_alert['email'])
def _send_email(): # Send email in a loop, avoid sending simultaneously. sq = Sql() items = sq.check_item_need_to_remind() logging.warning('This loop sent email: %s', items) for item in items: # email, item_name, item_price, user_price, item_id, column_id item_url = 'https://item.jd.com/' + str(item[4]) + '.html' email_text = '您监控的物品:' + item[1] + ',现在价格为:' + item[2] + \ ',您设定的价格为:' + item[3] + ',赶紧购买吧!' + item_url email_subject = '您监控的物品降价了!' try: send_email = Mail(email_text, 'admin', 'user', email_subject, item[0]) send_email.send() time.sleep(Email_TIME) except: logging.critical('Sent email failure, skip in this loop: %s', item[0]) continue sq.update_status(item[5]) logging.warning('Sent email SUCCESS: %s', item[0])