feat: 初始化
This commit is contained in:
1 parent
fd7abf141c
commit
9a447daaca
21 files changed
+244
-7
No files matched your search
@@ -0,0 +1,69 @@
|
||||
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 .config import Config
|
||||
from nonebot import on_command
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.adapters import Message
|
||||
from nonebot.params import Arg, CommandArg, ArgPlainText
|
||||
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())
|
||||
)
|
||||
|
||||
zhibo8Command = on_command("/zhibo8", rule=to_me(), aliases={'预测', '英超', 'zhibo'}, priority=10)
|
||||
|
||||
xiaobianStr = r"""
|
||||
小编们预测比分:
|
||||
太能喵:
|
||||
叶小欢:
|
||||
大帝强:
|
||||
小小:
|
||||
"""
|
||||
|
||||
|
||||
@zhibo8Command.handle()
|
||||
async def handler_zhibo8(bot: Bot, event: Event, state: T_State):
|
||||
session = HTMLSession()
|
||||
zhibo8Get = session.get("http://www.zhibo8.cc")
|
||||
print(zhibo8Get)
|
||||
saishiContent = zhibo8Get.html.xpath("//ul/li[starts-with(@id, 'saishi')]")
|
||||
vsMap = dict()
|
||||
# 解析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)
|
||||
|
||||
resultStr = ""
|
||||
for roudNum in vsMap:
|
||||
resultStr += "【" + roudNum.replace("第", "联赛 第") + " 比分预测】\r\n"
|
||||
for vs in vsMap[roudNum]:
|
||||
resultStr += vs + "\r\n"
|
||||
resultStr += xiaobianStr
|
||||
await zhibo8Command.finish(resultStr)
|
||||
|
||||
|
||||
def parserSaishiItem(saishiStr):
|
||||
html = HTML(html=saishiStr)
|
||||
listItem = html.xpath("//b//text()")
|
||||
roundNum = listItem[0].split(" ")[0].strip()
|
||||
homeName = listItem[0].split(" ")[1].strip()
|
||||
awayName = listItem[-1].strip()
|
||||
timeStr = html.xpath("//li/@data-time")
|
||||
time = datetime.strptime(timeStr[0], "%Y-%m-%d %H:%M")
|
||||
return (roundNum, time.strftime("%m月%d日%H:%M") + " " + homeName + " vs " + awayName)
|
||||
@@ -0,0 +1,5 @@
|
||||
from pydantic import BaseModel, Extra
|
||||
|
||||
|
||||
class Config(BaseModel, extra=Extra.ignore):
|
||||
"""Plugin Config Here"""
|
||||
Reference in new issue
Block a user