Skip to content

Commit

Permalink
Update getnews.py
Browse files Browse the repository at this point in the history
  • Loading branch information
congxuma committed May 7, 2023
1 parent 257017e commit 1161404
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions plugins/plugin_getnews/getnews.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ def on_handle_context(self, e_context: EventContext):
e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑

if re.search(r"微博|weibo|wb", content) and len(content) <= 5:
reply = Reply()
reply.type = ReplyType.TEXT

#接口信息 https://tophub.today/ | https://www.alapi.cn/api/view/49

url = "https://v2.alapi.cn/api/tophub"
headers = {'Content-Type': "application/x-www-form-urlencoded"}
payload = "token="+getnews_api_token+"&id=KqndgxeLl9"

#获取新闻
req = requests.request("POST", url, data=payload, headers=headers)
news_json = json.loads(req.text)

news_date = news_json['data']['last_update']

output = news_date + ' 更新\n'
for i in range(15):
item = f'%2s.' %str(i+1) + news_json['data']['list'][i]['title'] + ' / '+ news_json['data']['list'][i]['other'] + '\n'
output= output + item

reply.content = output

e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑

if re.match(r"我是.*", content) and len(content) <= 12:
reply = Reply()
reply.type = ReplyType.TEXT
Expand Down

0 comments on commit 1161404

Please sign in to comment.