Merge pull request #16 from NoobHumiliator/complex_calendar

增加日报提醒功能,在工作日  提醒发日报周报月报提醒
This commit is contained in:
Changhua
2023-10-02 17:58:15 +08:00
committed by GitHub
5 changed files with 69 additions and 0 deletions

View File

@@ -44,6 +44,9 @@ groups:
news:
receivers: [] # 定时新闻接收人roomid 或者 wxid
report_reminder:
receivers: [] # 定时日报周报月报提醒roomid 或者 wxid
# 如果要使用 ChatGPT取消下面的注释并填写相关内容
# chatgpt:
# key: 填写你 ChatGPT 的 key

View File

@@ -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")

60
func_report_reminder.py Normal file
View File

@@ -0,0 +1,60 @@
import datetime
import calendar
from chinese_calendar import is_workday
from robot import Robot
class ReportReminder:
@staticmethod
def remind(robot: 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

View File

@@ -6,6 +6,7 @@ import signal
from wcferry import Wcf
from configuration import Config
from func_report_reminder import ReportReminder
from robot import Robot
@@ -50,6 +51,9 @@ def main():
# 每天 7:30 发送新闻
robot.onEveryTime("07:30", robot.newsReport)
# 每天 16:30 提醒发日报周报月报
robot.onEveryTime("16:30", ReportReminder.remind, robot=robot)
# 让机器人一直跑
robot.keepRunningAndBlockProcess()

View File

@@ -5,3 +5,4 @@ pyyaml
requests
schedule
wcferry>=39.0.0.1
chinese_calendar