Impl news report

This commit is contained in:
Changhua
2023-04-16 23:47:18 +08:00
parent d996a46768
commit 925025a72a
4 changed files with 18 additions and 1 deletions

View File

@@ -41,6 +41,9 @@ logging:
groups:
enable: [] # 允许响应的群 roomId大概长这样2xxxxxxxxx3@chatroom
news:
receivers: [] # 定时新闻接收人roomid 或者 wxid
# 如果要使用 ChatGPT取消下面的注释并填写相关内容
# chatgpt:
# key: 填写你 ChatGPT 的 key

View File

@@ -30,3 +30,4 @@ class Config(object):
self.GROUPS = yconfig["groups"]["enable"]
self.CHATGPT = yconfig.get("chatgpt")
self.HTTP = yconfig.get("http")
self.NEWS = yconfig["news"]["receivers"]

View File

@@ -50,9 +50,12 @@ def main():
# 接收消息
robot.enableRecvMsg()
# 每天7点发送天气预报
# 每天 7 点发送天气预报
robot.onEveryTime("07:00", weather_report, robot=robot)
# 每天 7:30 发送新闻
robot.onEveryTime("07:30", robot.newsReport)
# 让机器人一直跑
robot.keepRunningAndBlockProcess()

View File

@@ -11,6 +11,7 @@ from configuration import Config
from func_chatgpt import ChatGPT
from func_chengyu import cy
from func_http import Http
from func_news import News
from job_mgmt import Job
@@ -200,3 +201,12 @@ class Robot(Job):
description=f"Github: <a href='{home}'>WeChatFerry</a>",)
Http.start(http, c["host"], c["port"])
self.LOG.info(f"HTTP listening on http://{c['host']}:{c['port']}")
def newsReport(self) -> None:
receivers = self.config.NEWS
if not receivers:
return
news = News().get_important_news()
for r in receivers:
self.sendTextMsg(news, r)