本帖最后由 wkdxz 于 2022-9-16 11:54 编辑
谢谢楼主分享的API,搞了个文字版,有兴趣的朋友拿走吧,需要套用企业微信API
[Python] 纯文本查看 复制代码 import datetime
import re
import requests
stoday = datetime.datetime.now().strftime('%Y-%m-%d')
def send_wx(msg):
corpid = '***'
corpsecret = '***-**'
appid = '***'
url = f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={corpsecret}'
r = requests.get(url, timeout=5)
tokens = r.json()['access_token']
url = f"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={tokens}"
data = {
"touser": "@all",
"msgtype": "text",
"agentid": appid,
"text": {
"content": msg
},
"safe": 0,
}
rtxt = requests.post(url, json=data, timeout=9).json()
return rtxt['errcode'] == 0 and rtxt['errmsg'] == 'ok'
def news_60s():
response = requests.get(
'https://www.zhihu.com/api/v4/columns/c_1261258401923026944/items')
html = response.json()['data'][0]['content']
cmd = r'data-pid="[^"]*">(\d+、[^;]*);</p>'
results = re.findall(cmd, html, re.S)
results.insert(0, f'{stoday} · 60秒新闻')
return '\n\n'.join(results).replace('"', '"')
if __name__ == '__main__':
news = news_60s()
print(news)
print(send_wx(news))
|