Compare commits
6
Commits
master
..
f84cd3cdfc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f84cd3cdfc | ||
|
|
837593ab11 | ||
|
|
b7c3a549dd | ||
|
|
24b6d4ca44 | ||
|
|
5eb218cf65 | ||
|
|
2465e0b748 |
@@ -1,3 +1,2 @@
|
|||||||
ENVIRONMENT=prod
|
ENVIRONMENT=prod
|
||||||
DRIVER=~fastapi
|
DRIVER=~fastapi
|
||||||
FEISHU_BOTS=[{"app_id":"cli_a58e99809818d00c","app_secret":"4tY3KSlogZZ0qR6wxq5pTb05adfVcxJU","verification_token":"ZHdJF5ruJFOhVDgvsrfEMbNsil643caV","encrypt_key":"xiaoyan159","is_lark":false}]
|
|
||||||
@@ -140,3 +140,5 @@ dmypy.json
|
|||||||
# End of https://www.toptal.com/developers/gitignore/api/python
|
# End of https://www.toptal.com/developers/gitignore/api/python
|
||||||
.idea
|
.idea
|
||||||
cqhttp/data
|
cqhttp/data
|
||||||
|
session.token
|
||||||
|
device.json
|
||||||
|
|||||||
Generated
-3
@@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
Generated
-11
@@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="PYTHON_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
-6
@@ -1,6 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<settings>
|
|
||||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
|
||||||
<version value="1.0" />
|
|
||||||
</settings>
|
|
||||||
</component>
|
|
||||||
Generated
-4
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
|
|
||||||
</project>
|
|
||||||
Generated
-8
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/NoneBot-Xiao.iml" filepath="$PROJECT_DIR$/.idea/NoneBot-Xiao.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -1,12 +1,20 @@
|
|||||||
import nonebot
|
import nonebot
|
||||||
from nonebot.adapters.feishu import Adapter as FeishuAdapter
|
from nonebot.adapters.onebot.v11 import Adapter as ONEBOT_V11Adapter
|
||||||
|
|
||||||
|
# from nonebot.adapters.feishu import Adapter as 飞书Adapter
|
||||||
|
#
|
||||||
|
# from nonebot.adapters.ntchat import Adapter as NTCHATAdapter
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
nonebot.init()
|
nonebot.init()
|
||||||
|
|
||||||
driver = nonebot.get_driver()
|
driver = nonebot.get_driver()
|
||||||
driver.register_adapter(FeishuAdapter)
|
driver.register_adapter(ONEBOT_V11Adapter)
|
||||||
|
|
||||||
|
# driver.register_adapter(飞书Adapter)
|
||||||
|
#
|
||||||
|
# driver.register_adapter(NTCHATAdapter)
|
||||||
|
|
||||||
nonebot.load_builtin_plugins('echo')
|
nonebot.load_builtin_plugins('echo')
|
||||||
|
|
||||||
|
|||||||
Regular → Executable
Regular → Executable
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://ishkong.github.io/go-cqhttp-docs/">
|
<a href="https://ishkong.github.io/go-cqhttp-docs/">
|
||||||
<img src="https://user-images.githubusercontent.com/25968335/120111974-8abef880-c139-11eb-99cd-fa928348b198.png" width="200" height="200" alt="go-cqhttp">
|
<img src="winres/icon.png" width="200" height="200" alt="go-cqhttp">
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|||||||
+16
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
account: # 账号相关
|
account: # 账号相关
|
||||||
uin: 1648107533 # QQ账号
|
uin: 1648107533 # QQ账号
|
||||||
password: 'xiaoyan159062' # 密码为空时使用扫码登录
|
password: '' # 密码为空时使用扫码登录
|
||||||
encrypt: false # 是否开启密码加密
|
encrypt: false # 是否开启密码加密
|
||||||
status: 0 # 在线状态 请参考 https://docs.go-cqhttp.org/guide/config.html#在线状态
|
status: 0 # 在线状态 请参考 https://docs.go-cqhttp.org/guide/config.html#在线状态
|
||||||
relogin: # 重连设置
|
relogin: # 重连设置
|
||||||
@@ -16,6 +16,15 @@ account: # 账号相关
|
|||||||
# 是否允许发送临时会话消息
|
# 是否允许发送临时会话消息
|
||||||
allow-temp-session: false
|
allow-temp-session: false
|
||||||
|
|
||||||
|
# 数据包的签名服务器
|
||||||
|
# 兼容 https://github.com/fuqiuluo/unidbg-fetch-qsign
|
||||||
|
# 如果遇到 登录 45 错误, 或者发送信息风控的话需要填入一个服务器
|
||||||
|
# 示例:
|
||||||
|
# sign-server: 'http://127.0.0.1:8080' # 本地签名服务器
|
||||||
|
# sign-server: 'https://signserver.example.com' # 线上签名服务器
|
||||||
|
# 服务器可使用docker在本地搭建或者使用他人开放的服务
|
||||||
|
sign-server: 'http://127.0.0.1:5709/'
|
||||||
|
|
||||||
heartbeat:
|
heartbeat:
|
||||||
# 心跳频率, 单位秒
|
# 心跳频率, 单位秒
|
||||||
# -1 为关闭心跳
|
# -1 为关闭心跳
|
||||||
@@ -43,6 +52,10 @@ message:
|
|||||||
extra-reply-data: false
|
extra-reply-data: false
|
||||||
# 跳过 Mime 扫描, 忽略错误数据
|
# 跳过 Mime 扫描, 忽略错误数据
|
||||||
skip-mime-scan: false
|
skip-mime-scan: false
|
||||||
|
# 是否自动转换 WebP 图片
|
||||||
|
convert-webp-image: false
|
||||||
|
# http超时时间
|
||||||
|
http-timeout: 0
|
||||||
|
|
||||||
output:
|
output:
|
||||||
# 日志等级 trace,debug,info,warn,error
|
# 日志等级 trace,debug,info,warn,error
|
||||||
@@ -105,3 +118,5 @@ servers:
|
|||||||
reconnect-interval: 3000
|
reconnect-interval: 3000
|
||||||
middlewares:
|
middlewares:
|
||||||
<<: *default # 引用默认中间件
|
<<: *default # 引用默认中间件
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
{"display":"MIRAI.030468.001","product":"mirai","device":"mirai","board":"mirai","model":"mirai","finger_print":"mamoe/mirai/mirai:10/MIRAI.200122.001/4241523:user/release-keys","boot_id":"0624e782-cfa9-b123-f253-482e3695d1bf","proc_version":"Linux version 3.0.31-RwxaY2Wt (android-build@xxx.xxx.xxx.xxx.com)","protocol":5,"imei":"935895209282990","brand":"mamoe","bootloader":"unknown","base_band":"","version":{"incremental":"5891938","release":"10","codename":"REL","sdk":29},"sim_info":"T-Mobile","os_type":"android","mac_address":"00:50:56:C0:00:08","ip_address":[10,0,1,3],"wifi_bssid":"00:50:56:C0:00:08","wifi_ssid":"\u003cunknown ssid\u003e","imsi_md5":"b9424c49d46505d1f2c99e9bbadd340f","android_id":"cc1733e21c8ea405","apn":"wifi","vendor_name":"MIUI","vendor_os_name":"mirai"}
|
{"display":"MIRAI.495990.001","product":"mirai","device":"mirai","board":"mirai","model":"mirai","finger_print":"mamoe/mirai/mirai:10/MIRAI.200122.001/4144447:user/release-keys","boot_id":"46ffb647-de87-258d-bb07-eb08e3a29b33","proc_version":"Linux version 3.0.31-10kFFebM (android-build@xxx.xxx.xxx.xxx.com)","protocol":2,"imei":"435775380963712","brand":"mamoe","bootloader":"unknown","base_band":"","version":{"incremental":"5891938","release":"10","codename":"REL","sdk":29},"sim_info":"T-Mobile","os_type":"android","mac_address":"00:50:56:C0:00:08","ip_address":[10,0,1,3],"wifi_bssid":"00:50:56:C0:00:08","wifi_ssid":"\u003cunknown ssid\u003e","imsi_md5":"9bc76fd297d1536030d19c2ef497b691","android_id":"1eabadb09bae30c0","apn":"wifi","vendor_name":"MIUI","vendor_os_name":"mirai"}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,73 @@
|
|||||||
|
aiocache==0.12.0
|
||||||
|
aiocqhttp==1.4.3
|
||||||
|
aiofiles==23.1.0
|
||||||
|
anyio==3.6.2
|
||||||
|
appdirs==1.4.4
|
||||||
|
beautifulsoup4==4.11.2
|
||||||
|
blinker==1.5
|
||||||
|
bs4==0.0.1
|
||||||
|
certifi==2022.12.7
|
||||||
|
charset-normalizer==3.0.1
|
||||||
|
click==8.1.3
|
||||||
|
colorama==0.4.6
|
||||||
|
cssselect==1.2.0
|
||||||
|
docopt==0.6.2
|
||||||
|
fake-useragent==1.1.1
|
||||||
|
fastapi==0.91.0
|
||||||
|
h11==0.14.0
|
||||||
|
h2==4.1.0
|
||||||
|
hpack==4.0.0
|
||||||
|
html5lib==1.1
|
||||||
|
httpcore==0.16.3
|
||||||
|
httptools==0.5.0
|
||||||
|
httpx==0.23.3
|
||||||
|
hypercorn==0.14.3
|
||||||
|
hyperframe==6.0.1
|
||||||
|
idna==3.4
|
||||||
|
importlib-metadata==6.0.0
|
||||||
|
irc3==1.1.8
|
||||||
|
itsdangerous==2.1.2
|
||||||
|
Jinja2==3.1.2
|
||||||
|
lfmh==1.1.1
|
||||||
|
loguru==0.6.0
|
||||||
|
lxml==4.9.2
|
||||||
|
MarkupSafe==2.1.2
|
||||||
|
msgpack==1.0.4
|
||||||
|
multidict==6.0.4
|
||||||
|
musicbrainzngs==0.7.1
|
||||||
|
nonebot-adapter-onebot==2.2.1
|
||||||
|
nonebot2==2.0.0rc3
|
||||||
|
onebot==1.3.3
|
||||||
|
parse==1.19.0
|
||||||
|
priority==2.0.0
|
||||||
|
pydantic==1.10.4
|
||||||
|
pyee==8.2.2
|
||||||
|
pygtrie==2.5.0
|
||||||
|
pyppeteer==1.0.2
|
||||||
|
pyquery==2.0.0
|
||||||
|
python-dotenv==0.21.1
|
||||||
|
PyYAML==6.0
|
||||||
|
quart==0.18.3
|
||||||
|
requests==2.28.2
|
||||||
|
requests-html==0.10.0
|
||||||
|
rfc3986==1.5.0
|
||||||
|
six==1.16.0
|
||||||
|
sniffio==1.3.0
|
||||||
|
soupsieve==2.3.2.post1
|
||||||
|
starlette==0.24.0
|
||||||
|
toml==0.10.2
|
||||||
|
tomlkit==0.11.6
|
||||||
|
tqdm==4.64.1
|
||||||
|
typing_extensions==4.4.0
|
||||||
|
urllib3==1.26.14
|
||||||
|
uvicorn==0.20.0
|
||||||
|
venusian==3.0.0
|
||||||
|
w3lib==2.1.1
|
||||||
|
watchfiles==0.18.1
|
||||||
|
webencodings==0.5.1
|
||||||
|
websockets==10.4
|
||||||
|
Werkzeug==2.2.2
|
||||||
|
win32-setctime==1.1.0
|
||||||
|
wsproto==1.2.0
|
||||||
|
yarl==1.8.2
|
||||||
|
zipp==3.13.0
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
import nonebot
|
||||||
|
from nonebot import get_driver, on_message
|
||||||
|
from nonebot.adapters.onebot.v11 import Bot, Event
|
||||||
|
from nonebot.typing import T_State
|
||||||
|
from nonebot.params import CommandArg
|
||||||
|
from nonebot.message import event_preprocessor
|
||||||
|
|
||||||
|
from .config import Config
|
||||||
|
from nonebot import on_command
|
||||||
|
from nonebot.rule import to_me
|
||||||
|
from requests_html import HTMLSession, HTML
|
||||||
|
|
||||||
|
global_config = get_driver().config
|
||||||
|
config = Config.parse_obj(global_config)
|
||||||
|
|
||||||
|
_sub_plugins = set()
|
||||||
|
_sub_plugins |= nonebot.load_plugins(
|
||||||
|
str((Path(__file__).parent / "plugins").resolve())
|
||||||
|
)
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from pydantic import BaseModel, Extra
|
||||||
|
|
||||||
|
|
||||||
|
class Config(BaseModel, extra=Extra.ignore):
|
||||||
|
"""Plugin Config Here"""
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from nonebot.adapters.onebot.v11 import Bot, Event
|
||||||
|
from nonebot.typing import T_State
|
||||||
|
from nonebot.params import CommandArg, Command
|
||||||
|
|
||||||
|
from nonebot import on_command
|
||||||
|
from nonebot.rule import to_me
|
||||||
|
from requests_html import HTMLSession, HTML
|
||||||
|
|
||||||
|
zhibo8Command = on_command("/zhibo8", rule=to_me(), aliases={'预测', '英超', 'zhibo8'}, priority=10)
|
||||||
|
|
||||||
|
xiaobianStr = r"""
|
||||||
|
小编们预测比分:
|
||||||
|
太能喵:
|
||||||
|
叶小欢:
|
||||||
|
大帝强:
|
||||||
|
小小:
|
||||||
|
"""
|
||||||
|
vsMap = {}
|
||||||
|
@zhibo8Command.handle()
|
||||||
|
async def handle_first_receive(bot: Bot, event: Event, state: T_State, args= CommandArg()):
|
||||||
|
# 事件预处理,获取对应的赛程数据
|
||||||
|
vsMap.clear()
|
||||||
|
session = HTMLSession()
|
||||||
|
zhibo8Get = session.get("https://www.zhibo8.cc/")
|
||||||
|
print(zhibo8Get)
|
||||||
|
saishiContent = zhibo8Get.html.xpath("//div[@class='vct-box']/div[@class='_content']/ul/li")
|
||||||
|
# 解析xpath
|
||||||
|
# 解析xpath
|
||||||
|
for item in saishiContent:
|
||||||
|
if item.html.find("英超") >= 0:
|
||||||
|
if item.html.find("阿森纳") >= 0 or item.html.find("曼城") >= 0 or item.html.find("曼联") >= 0 or item.html.find(
|
||||||
|
"利物浦") >= 0 or item.html.find("切尔西") >= 0:
|
||||||
|
rouneNum, vsStr = parserSaishiItem(item.html)
|
||||||
|
if rouneNum not in vsMap.keys():
|
||||||
|
vsMap[rouneNum] = []
|
||||||
|
vsMap[rouneNum].append(vsStr)
|
||||||
|
|
||||||
|
plain_text = args.extract_plain_text()
|
||||||
|
if plain_text:
|
||||||
|
state.set_arg("round", plain_text)
|
||||||
|
else:
|
||||||
|
await zhibo8Command.send(message=""""选择要查看的轮次,当前支持查看的轮次为:\r\n{} \r\n""".format(getRoundPrompt(vsMap)))
|
||||||
|
|
||||||
|
@zhibo8Command.got(key="round", prompt="""请输入编号:""")
|
||||||
|
async def getRoundNum(event: Event):
|
||||||
|
round = str(event.get_message())
|
||||||
|
if round.isdigit() == False:
|
||||||
|
await zhibo8Command.reject(prompt="请输入编号(数字)")
|
||||||
|
if len(vsMap.keys())>=int(round):
|
||||||
|
resultStr = ""
|
||||||
|
roudNum = list(vsMap.keys())[int(round)-1]
|
||||||
|
# for roudNum in vsMap:
|
||||||
|
resultStr += "【" + roudNum.replace("第", "联赛 第") + " 比分预测】\r\n"
|
||||||
|
for vs in vsMap[roudNum]:
|
||||||
|
resultStr += vs + xiaobianStr + "\r\n"
|
||||||
|
await zhibo8Command.finish(resultStr)
|
||||||
|
else:
|
||||||
|
await zhibo8Command.reject_arg(key="round", prompt="输入的编号错误,请重新输入!")
|
||||||
|
|
||||||
|
def parserSaishiItem(saishiStr):
|
||||||
|
html = HTML(html=saishiStr)
|
||||||
|
# listItem = html.xpath("//b//text()")
|
||||||
|
roundNum = html.xpath("//span[@class='_league']//text()")[0]
|
||||||
|
homeName = html.xpath("//span[@class='_teams']//text()")[0].strip()
|
||||||
|
awayName = html.xpath("//span[@class='_teams']//text()")[-1].strip()
|
||||||
|
timeStr = html.xpath("./li/@data-time")[0]
|
||||||
|
time = datetime.strptime(timeStr, "%Y-%m-%d %H:%M")
|
||||||
|
timeTuple = time.timetuple()
|
||||||
|
return (roundNum, "{}月{}日".format(timeTuple.tm_mon, timeTuple.tm_mday)+time.strftime("%H:%M") + " " + homeName + " vs " + awayName)
|
||||||
|
|
||||||
|
|
||||||
|
def getRoundPrompt(roundMap):
|
||||||
|
str = ""
|
||||||
|
i = 1
|
||||||
|
for key in roundMap:
|
||||||
|
print(key)
|
||||||
|
str += "{}: {} \r\n".format(i, key)
|
||||||
|
i = i+1
|
||||||
|
return str
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
import datetime
|
||||||
|
import warnings
|
||||||
|
from datetime import timedelta
|
||||||
|
from nonebot.adapters.onebot.v11 import Bot, Event
|
||||||
|
from nonebot.typing import T_State
|
||||||
|
from nonebot.params import CommandArg, Command
|
||||||
|
|
||||||
|
from nonebot import on_command
|
||||||
|
from nonebot.rule import to_me
|
||||||
|
from requests_html import HTMLSession, HTML
|
||||||
|
import json
|
||||||
|
from selenium.webdriver import Chrome, ChromeOptions
|
||||||
|
|
||||||
|
|
||||||
|
driver_path = '../../../../driver/cromedriver_win32'
|
||||||
|
max_behot_time = '0'
|
||||||
|
# 初始化map对象,分别记录每个人的微头条个数
|
||||||
|
weitoutiaoMap = {"太能喵": 0, "小小": 0, "大帝强": 0, "叶小欢": 0}
|
||||||
|
|
||||||
|
"""
|
||||||
|
获取微头条数据信息
|
||||||
|
"""
|
||||||
|
def getWeiToutiaoInfo():
|
||||||
|
global max_behot_time
|
||||||
|
# 获取上一周的第一天和最后一天的时间戳
|
||||||
|
lastWeekStartTime, lastWeekEndTime = getLastWeekFirstDayTimeStamp()
|
||||||
|
session = HTMLSession()
|
||||||
|
weitoutiaoGet = session.get(f"https://www.toutiao.com/api/pc/list/user/feed?category=pc_profile_ugc&token=MS4wLjABAAAA7lHc4sBPuZaQ85qdIrwVvWm8Ps5O1kPMpuh5lTJAwII&max_behot_time={max_behot_time}&aid=24&app_name=toutiao_web", verify=False, proxies=None)
|
||||||
|
# print(weitoutiaoGet.text)
|
||||||
|
# 使用Json解析返回的数据
|
||||||
|
resultJson = json.loads(weitoutiaoGet.text)
|
||||||
|
# 先获取下个max_behot_time时间戳,如果需要翻页查询需要使用该参数
|
||||||
|
max_behot_time = resultJson['next']['max_behot_time']
|
||||||
|
# 开始循环解析data数据,获取微头条的内容和发布人员
|
||||||
|
dataList = resultJson['data']
|
||||||
|
# 获取每一条消息的发布时间戳,如果发布时间出现早于上周一0点的数据,结束统计,函数返回,否则递归调用当前函数
|
||||||
|
for data in dataList:
|
||||||
|
# 获取本条新闻的发布时间
|
||||||
|
publishTime = data["publish_time"]
|
||||||
|
if int(publishTime) > int(lastWeekEndTime):
|
||||||
|
continue
|
||||||
|
elif int(publishTime) < int(lastWeekStartTime):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
# 如果是比分预测类的微头条,则跳过
|
||||||
|
content = str(data['content'])
|
||||||
|
if content.find("比分预测】")>0:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
# 获取该微头条的发布人和发布日期
|
||||||
|
author = None
|
||||||
|
contentSubString = content[-8]
|
||||||
|
if contentSubString.find("太能喵")>0:
|
||||||
|
weitoutiaoMap["太能喵"] = weitoutiaoMap["太能喵"]+1
|
||||||
|
elif contentSubString.find("小小")>0:
|
||||||
|
weitoutiaoMap["小小"] = weitoutiaoMap["小小"]+1
|
||||||
|
elif contentSubString.find("大帝强") > 0:
|
||||||
|
weitoutiaoMap["大帝强"] = weitoutiaoMap["大帝强"] + 1
|
||||||
|
elif contentSubString.find("叶小欢") > 0:
|
||||||
|
weitoutiaoMap["叶小欢"] = weitoutiaoMap["叶小欢"] + 1
|
||||||
|
getWeiToutiaoInfo()
|
||||||
|
|
||||||
|
"""
|
||||||
|
获取文章数据信息
|
||||||
|
"""
|
||||||
|
def getWenzhangInfo():
|
||||||
|
global max_behot_time
|
||||||
|
|
||||||
|
# 第一步输入这个:去除开头警告
|
||||||
|
warnings.simplefilter('ignore', ResourceWarning)
|
||||||
|
|
||||||
|
chrome_option = ChromeOptions()
|
||||||
|
chrome_option.headless = True
|
||||||
|
chrome_option.add_argument('--no-sandbox') # 解决DevToolsActivePort文件不存在的报错
|
||||||
|
chrome_option.add_argument('--disable-gpu') # 谷歌文档提到需要加上这个属性来规避bug
|
||||||
|
chrome_option.add_argument('--hide-scrollbars') # 隐藏滚动条, 应对一些特殊页面
|
||||||
|
chrome_option.add_argument('--headless')
|
||||||
|
|
||||||
|
browser = Chrome(executable_path=driver_path, options=chrome_option)
|
||||||
|
|
||||||
|
# 获取上一周的第一天和最后一天的时间戳
|
||||||
|
lastWeekStartTime, lastWeekEndTime = getLastWeekFirstDayTimeStamp()
|
||||||
|
session = HTMLSession()
|
||||||
|
wenzhangGet = session.get(f"https://www.toutiao.com/api/pc/list/user/feed?category=pc_profile_article&token=MS4wLjABAAAA7lHc4sBPuZaQ85qdIrwVvWm8Ps5O1kPMpuh5lTJAwII&max_behot_time={max_behot_time}&aid=24&app_name=toutiao_web", verify=False, proxies=None)
|
||||||
|
# print(weitoutiaoGet.text)
|
||||||
|
# 使用Json解析返回的数据
|
||||||
|
resultJson = json.loads(wenzhangGet.text)
|
||||||
|
# 先获取下个max_behot_time时间戳,如果需要翻页查询需要使用该参数
|
||||||
|
max_behot_time = resultJson['next']['max_behot_time']
|
||||||
|
# 开始循环解析data数据,获取微头条的内容和发布人员
|
||||||
|
dataList = resultJson['data']
|
||||||
|
# 获取每一条消息的发布时间戳,如果发布时间出现早于上周一0点的数据,结束统计,函数返回,否则递归调用当前函数
|
||||||
|
for data in dataList:
|
||||||
|
# 获取本条新闻的发布时间
|
||||||
|
publishTime = data["publish_time"]
|
||||||
|
if int(publishTime) > int(lastWeekEndTime):
|
||||||
|
continue
|
||||||
|
elif int(publishTime) < int(lastWeekStartTime):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
# 获取该文章的标题和对应的url,需要再通过url获取文章正文,解析作者是谁
|
||||||
|
title = data["title"]
|
||||||
|
url = data["url"]
|
||||||
|
if url:
|
||||||
|
# 请求文章正文内容
|
||||||
|
wenzhangGet = browser.get(url)
|
||||||
|
print(wenzhangGet.text)
|
||||||
|
# author = None
|
||||||
|
# if data.find("太能喵")>0:
|
||||||
|
# weitoutiaoMap["太能喵"] = weitoutiaoMap["太能喵"]+1
|
||||||
|
# elif content.find("小小")>0:
|
||||||
|
# weitoutiaoMap["小小"] = weitoutiaoMap["小小"]+1
|
||||||
|
# elif content.find("大帝强") > 0:
|
||||||
|
# weitoutiaoMap["大帝强"] = weitoutiaoMap["大帝强"] + 1
|
||||||
|
# elif content.find("叶小欢") > 0:
|
||||||
|
# weitoutiaoMap["叶小欢"] = weitoutiaoMap["叶小欢"] + 1
|
||||||
|
# 如果没有被return掉,继续请求下一页内容
|
||||||
|
getWeiToutiaoInfo()
|
||||||
|
|
||||||
|
"""
|
||||||
|
获取当前日期上一周的第一天和最后一天的时间戳
|
||||||
|
"""
|
||||||
|
def getLastWeekFirstDayTimeStamp():
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
# 上周第一天和最后一天
|
||||||
|
last_week_start = now - timedelta(days=now.weekday() + 7, hours=now.hour, minutes=now.minute, seconds=now.second, microseconds=now.microsecond)
|
||||||
|
last_week_end = last_week_start - timedelta(days=-7)
|
||||||
|
print(f"上周第一天的日期是:{last_week_start},最后一天的日期是:{last_week_end}")
|
||||||
|
print(f"上周第一天的时间戳是:{last_week_start.timestamp()},最后一天的时间戳是:{last_week_end.timestamp()}")
|
||||||
|
return last_week_start.timestamp(), last_week_end.timestamp()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
getWenzhangInfo()
|
||||||
|
# print(weitoutiaoMap)
|
||||||
Reference in New Issue
Block a user