每周自动发送电子邮件

时间:2019-11-06 07:50:59

标签: python python-3.x

我想每周星期一@ 10 am每周发送一次自动电子邮件报告,但是以下代码不起作用。每隔1个小时每周都会触发一次。请帮忙

下面是我编写的代码。

def send_daily():

        '''Check reports to be sent daily'''

  current_day = calendar.day_name[now_datetime().weekday()]
        now = frappe.utils.now_datetime()

        current_time = now.strftime("%H")

        enabled_reports = frappe.get_all('Auto Email Report',

                filters={'enabled': 1, 'frequency': ('in', ('Daily', 'Weekdays', 'Weekly'))})

        for report in enabled_reports:

  auto_email_report = frappe.get_doc('Auto Email Report', report.name)

                # if not correct weekday, skip

if auto_email_report.frequency == "Weekdays":

  if current_day in ("Saturday", "Sunday"):

     continue

  elif auto_email_report.frequency == 'Weekly':

 if auto_email_report.day_of_week != current_day:

  if auto_email_report.schedule_time != current_time:

  continue
                elif auto_email_report.frequency == "Daily":

 if auto_email_report.schedule_time != current_time:

 continue


  auto_email_report.send()

我希望该电子邮件在每周星期一上午10点触发。

1 个答案:

答案 0 :(得分:0)

看起来像是按小时而不是按天触发...请尝试检查更改的是日期而非时间。