From 2b26698bd72427ac3091843a1545bdda2c67090d Mon Sep 17 00:00:00 2001 From: TechShrimp <939178127@qq.com> Date: Sun, 1 Oct 2023 21:47:07 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=90=E9=86=92?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=B7=A5=E4=BD=9C=E6=97=A5=E5=91=A8?= =?UTF-8?q?=E6=8A=A5=E6=9C=88=E6=8A=A5=E6=97=A5=E6=8A=A5=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml.template | 3 +++ configuration.py | 1 + main.py | 10 +++++--- report_reminder.py | 57 ++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 report_reminder.py diff --git a/config.yaml.template b/config.yaml.template index 0586434..9d507e6 100644 --- a/config.yaml.template +++ b/config.yaml.template @@ -44,6 +44,9 @@ groups: news: receivers: [] # 定时新闻接收人(roomid 或者 wxid) +report_reminder: + receivers: [] # 定时日报周报月报提醒(roomid 或者 wxid) + # 如果要使用 ChatGPT,取消下面的注释并填写相关内容 # chatgpt: # key: 填写你 ChatGPT 的 key diff --git a/configuration.py b/configuration.py index 7a96ac6..517d96e 100644 --- a/configuration.py +++ b/configuration.py @@ -30,4 +30,5 @@ class Config(object): self.GROUPS = yconfig["groups"]["enable"] self.CHATGPT = yconfig.get("chatgpt") self.NEWS = yconfig["news"]["receivers"] + self.REPORT_REMINDERS = yconfig["report_reminder"]["receivers"] self.TIGERBOT = yconfig.get("tigerbot") diff --git a/main.py b/main.py index c09d5a7..00f992b 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ import signal from wcferry import Wcf from configuration import Config +from report_reminder import ReportReminder from robot import Robot @@ -23,7 +24,6 @@ def weather_report(robot: Robot) -> None: robot.sendTextMsg(report, r) # robot.sendTextMsg(report, r, "nofity@all") # 发送消息并@所有人 - def main(): config = Config() wcf = Wcf(debug=True) @@ -38,7 +38,9 @@ def main(): robot.LOG.info("正在启动机器人···") # 机器人启动发送测试消息 - robot.sendTextMsg("机器人启动成功!", "filehelper") + # robot.sendTextMsg("机器人启动成功!", "filehelper") + # 打印全部微信联系人 + print(robot.getAllContacts()) # 接收消息 # robot.enableRecvMsg() # 可能会丢消息? @@ -48,7 +50,9 @@ def main(): robot.onEveryTime("07:00", weather_report, robot=robot) # 每天 7:30 发送新闻 - robot.onEveryTime("07:30", robot.newsReport) + #robot.onEveryTime("07:30", robot.newsReport) + + robot.onEveryTime("21:42", ReportReminder.remind, robot=robot) # 让机器人一直跑 robot.keepRunningAndBlockProcess() diff --git a/report_reminder.py b/report_reminder.py new file mode 100644 index 0000000..b76e909 --- /dev/null +++ b/report_reminder.py @@ -0,0 +1,57 @@ +import datetime +import calendar +from chinese_calendar import is_workday +from robot import Robot + + +class ReportReminder: + + @staticmethod + def remind(robot) -> None: + + receivers = robot.config.REPORT_REMINDERS + if not receivers: + receivers = ["filehelper"] + #日报周报月报提醒 + for receiver in receivers: + today = datetime.datetime.now().date() + # 如果是非工作日 + if not is_workday(today): + robot.sendTextMsg("休息日快乐", receiver) + # 如果是工作日 + if is_workday(today): + robot.sendTextMsg("该发日报啦", receiver) + # 如果是本周最后一个工作日 + if ReportReminder.last_work_day_of_week(today) == today: + robot.sendTextMsg("该发周报啦", receiver) + # 如果本日是本月最后一整周的最后一个一个工作日: + if ReportReminder.last_work_friday_of_month(today) == today: + robot.sendTextMsg("该发月报啦", receiver) + + # 计算本月最后一个周的最后一个工作日 + @staticmethod + def last_work_friday_of_month(d: datetime.date) -> datetime.date: + days_in_month = calendar.monthrange(d.year, d.month)[1] + weekday = calendar.weekday(d.year, d.month, days_in_month) + if weekday == 4: + last_friday_of_month = datetime.date(d.year, d.month, days_in_month) + else: + if weekday >= 5: + last_friday_of_month = datetime.date(d.year, d.month, days_in_month) - datetime.timedelta( + days=(weekday - 4)) + else: + last_friday_of_month = datetime.date(d.year, d.month, days_in_month) - datetime.timedelta( + days=(weekday + 3)) + while not is_workday(last_friday_of_month): + last_friday_of_month = last_friday_of_month - datetime.timedelta(days=1) + return last_friday_of_month + + # 计算本周最后一个工作日 + @staticmethod + def last_work_day_of_week(d: datetime.date) -> datetime.date: + weekday = calendar.weekday(d.year, d.month, d.day) + last_work_day_of_week = datetime.date(d.year, d.month, d.day) + datetime.timedelta(days=(6 - weekday)) + + while not is_workday(last_work_day_of_week): + last_work_day_of_week = last_work_day_of_week - datetime.timedelta(days=1) + return last_work_day_of_week diff --git a/requirements.txt b/requirements.txt index eac166b..43e9765 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ pyyaml requests schedule wcferry>=39.0.0.1 +chinese_calendar From 03e2ff90c9395a0c3697e15952127e07d15414e0 Mon Sep 17 00:00:00 2001 From: TechShrimp <939178127@qq.com> Date: Sun, 1 Oct 2023 21:53:59 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=90=E9=86=92?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=B7=A5=E4=BD=9C=E6=97=A5=E5=91=A8?= =?UTF-8?q?=E6=8A=A5=E6=9C=88=E6=8A=A5=E6=97=A5=E6=8A=A5=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 00f992b..62394dc 100644 --- a/main.py +++ b/main.py @@ -38,9 +38,7 @@ def main(): robot.LOG.info("正在启动机器人···") # 机器人启动发送测试消息 - # robot.sendTextMsg("机器人启动成功!", "filehelper") - # 打印全部微信联系人 - print(robot.getAllContacts()) + robot.sendTextMsg("机器人启动成功!", "filehelper") # 接收消息 # robot.enableRecvMsg() # 可能会丢消息? @@ -50,9 +48,10 @@ def main(): robot.onEveryTime("07:00", weather_report, robot=robot) # 每天 7:30 发送新闻 - #robot.onEveryTime("07:30", robot.newsReport) + robot.onEveryTime("07:30", robot.newsReport) - robot.onEveryTime("21:42", ReportReminder.remind, robot=robot) + # 每天 4:30 提醒发日报周报月报 + robot.onEveryTime("4:30", ReportReminder.remind, robot=robot) # 让机器人一直跑 robot.keepRunningAndBlockProcess() From 37414d3c3576e5452027583dd7666c3befb25721 Mon Sep 17 00:00:00 2001 From: TechShrimp <939178127@qq.com> Date: Sun, 1 Oct 2023 22:05:42 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=90=E9=86=92?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=B7=A5=E4=BD=9C=E6=97=A5=E5=91=A8?= =?UTF-8?q?=E6=8A=A5=E6=9C=88=E6=8A=A5=E6=97=A5=E6=8A=A5=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 62394dc..2e6d60c 100644 --- a/main.py +++ b/main.py @@ -50,8 +50,8 @@ def main(): # 每天 7:30 发送新闻 robot.onEveryTime("07:30", robot.newsReport) - # 每天 4:30 提醒发日报周报月报 - robot.onEveryTime("4:30", ReportReminder.remind, robot=robot) + # 每天 16:30 提醒发日报周报月报 + robot.onEveryTime("16:30", ReportReminder.remind, robot=robot) # 让机器人一直跑 robot.keepRunningAndBlockProcess() From 2cf42b8b53eaed1210531f90f279db9d7cebe223 Mon Sep 17 00:00:00 2001 From: TechShrimp <939178127@qq.com> Date: Mon, 2 Oct 2023 16:18:56 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=A0=B9=E6=8D=AEPR=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BF=AE=E6=94=B9=20=E4=BD=BF=E7=94=A8autope?= =?UTF-8?q?p8=E8=B0=83=E6=95=B4=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- report_reminder.py => func_report_reminder.py | 23 +++++++++++-------- main.py | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) rename report_reminder.py => func_report_reminder.py (76%) diff --git a/report_reminder.py b/func_report_reminder.py similarity index 76% rename from report_reminder.py rename to func_report_reminder.py index b76e909..1252fec 100644 --- a/report_reminder.py +++ b/func_report_reminder.py @@ -7,12 +7,12 @@ from robot import Robot class ReportReminder: @staticmethod - def remind(robot) -> None: + def remind(robot: Robot) -> None: receivers = robot.config.REPORT_REMINDERS if not receivers: receivers = ["filehelper"] - #日报周报月报提醒 + # 日报周报月报提醒 for receiver in receivers: today = datetime.datetime.now().date() # 如果是非工作日 @@ -24,7 +24,7 @@ class ReportReminder: # 如果是本周最后一个工作日 if ReportReminder.last_work_day_of_week(today) == today: robot.sendTextMsg("该发周报啦", receiver) - # 如果本日是本月最后一整周的最后一个一个工作日: + # 如果本日是本月最后一整周的最后一个工作日: if ReportReminder.last_work_friday_of_month(today) == today: robot.sendTextMsg("该发月报啦", receiver) @@ -34,14 +34,15 @@ class ReportReminder: days_in_month = calendar.monthrange(d.year, d.month)[1] weekday = calendar.weekday(d.year, d.month, days_in_month) if weekday == 4: - last_friday_of_month = datetime.date(d.year, d.month, days_in_month) + last_friday_of_month = datetime.date( + d.year, d.month, days_in_month) else: if weekday >= 5: - last_friday_of_month = datetime.date(d.year, d.month, days_in_month) - datetime.timedelta( - days=(weekday - 4)) + last_friday_of_month = datetime.date(d.year, d.month, days_in_month) - \ + datetime.timedelta(days=(weekday - 4)) else: - last_friday_of_month = datetime.date(d.year, d.month, days_in_month) - datetime.timedelta( - days=(weekday + 3)) + last_friday_of_month = datetime.date(d.year, d.month, days_in_month) - \ + datetime.timedelta(days=(weekday + 3)) while not is_workday(last_friday_of_month): last_friday_of_month = last_friday_of_month - datetime.timedelta(days=1) return last_friday_of_month @@ -50,8 +51,10 @@ class ReportReminder: @staticmethod def last_work_day_of_week(d: datetime.date) -> datetime.date: weekday = calendar.weekday(d.year, d.month, d.day) - last_work_day_of_week = datetime.date(d.year, d.month, d.day) + datetime.timedelta(days=(6 - weekday)) + last_work_day_of_week = datetime.date( + d.year, d.month, d.day) + datetime.timedelta(days=(6 - weekday)) while not is_workday(last_work_day_of_week): - last_work_day_of_week = last_work_day_of_week - datetime.timedelta(days=1) + last_work_day_of_week = last_work_day_of_week - \ + datetime.timedelta(days=1) return last_work_day_of_week diff --git a/main.py b/main.py index 2e6d60c..5e3288d 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ import signal from wcferry import Wcf from configuration import Config -from report_reminder import ReportReminder +from func_report_reminder import ReportReminder from robot import Robot @@ -24,6 +24,7 @@ def weather_report(robot: Robot) -> None: robot.sendTextMsg(report, r) # robot.sendTextMsg(report, r, "nofity@all") # 发送消息并@所有人 + def main(): config = Config() wcf = Wcf(debug=True)