【问题标题】:Weekly auto email每周自动电子邮件
【发布时间】:2019-11-06 07:50:59
【问题描述】:

我想每周一上午 10 点发送自动电子邮件报告,但以下代码不起作用。它每 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 点触发电子邮件。

【问题讨论】:

  • 格式代码。当前版本无用。投反对票。

标签: python python-3.x


【解决方案1】:

看起来您按小时而不是按天触发...尝试检查何时更改白天时间而不是小时。

【讨论】:

  • 谢谢@KmcASI 我会检查的
  • 我认为另一个解决方案是存储一些最后一次发送的位置,并在每天上午 10 点存储一些,以查看距离上次发送邮件是否已经过了一周或一个月。听起来很复杂,其实很简单
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-18
  • 2013-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-01
相关资源
最近更新 更多