2024-07-11 18:26:21 +08:00
|
|
|
|
import json
|
2024-08-15 18:22:24 +08:00
|
|
|
|
from typing import Dict
|
|
|
|
|
|
|
|
|
|
from aiohttp import ClientSession
|
|
|
|
|
|
|
|
|
|
from .models import *
|
2024-08-08 20:50:18 +08:00
|
|
|
|
from .util import *
|
2024-08-15 18:22:24 +08:00
|
|
|
|
|
|
|
|
|
CITY_API_ROOT = "https://show.bilibili.com/api/ticket/city/list?channel=3"
|
|
|
|
|
SHOWS_API_ROOT = "https://show.bilibili.com/api/ticket/project/listV2"
|
2024-07-11 18:26:21 +08:00
|
|
|
|
HEADERS = {
|
2024-08-22 22:50:18 +08:00
|
|
|
|
"user-agent": "Mozilla/5.0 (Linux; Android 14; 114514YAJU Build/UKQ1.114514.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/125.0.6422.165 Mobile Safari/537.36 BiliApp/7810200 mobi_app/android isNotchWindow/0 NotchHeight=34 mallVersion/7810200 mVersion/242 disable_rcmd/0 7.81.0 os/android model/114514YAJU mobi_app/android build/7810200 channel/bilih5 innerVer/7810210 osVer/14 network/2"
|
2024-08-15 18:22:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_cities_data() -> CityResp:
|
|
|
|
|
"""
|
|
|
|
|
返回支持的城市数据
|
|
|
|
|
"""
|
|
|
|
|
async with ClientSession() as session:
|
|
|
|
|
async with session.get(CITY_API_ROOT, headers=HEADERS) as resp:
|
|
|
|
|
regions_data = await resp.json()
|
|
|
|
|
return CityResp.model_validate(regions_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_regions_dict() -> Dict[str, int]:
|
|
|
|
|
"""
|
2024-07-11 18:26:21 +08:00
|
|
|
|
返回支持的地区,键名为地区名,键值为地区id
|
2024-08-15 18:22:24 +08:00
|
|
|
|
"""
|
|
|
|
|
data = {}
|
|
|
|
|
city_data = await get_cities_data()
|
|
|
|
|
for i in city_data.data.list:
|
|
|
|
|
for j in i.city_list:
|
2024-08-22 22:50:18 +08:00
|
|
|
|
data.update({j.name: j.id})
|
|
|
|
|
data.update({"全国": -1, "海外": 900000})
|
2024-08-15 18:22:24 +08:00
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_shows_data(region_id: int, page=1, pagesize=20):
|
|
|
|
|
"""
|
2024-07-11 18:26:21 +08:00
|
|
|
|
返回举办中/即将举办/取消举办的展览数据
|
|
|
|
|
Args:
|
|
|
|
|
region_id: 地区id
|
|
|
|
|
page: 页码
|
|
|
|
|
pagesize: 一页最大条目数,最大20
|
2024-08-15 18:22:24 +08:00
|
|
|
|
"""
|
2024-07-11 18:26:21 +08:00
|
|
|
|
param = {
|
2024-08-22 22:50:18 +08:00
|
|
|
|
"version": 133,
|
|
|
|
|
"area": region_id,
|
|
|
|
|
"page": page,
|
|
|
|
|
"pagesize": pagesize,
|
|
|
|
|
"platform": "web",
|
|
|
|
|
"p_type": "展览",
|
|
|
|
|
"style": 1,
|
2024-07-11 18:26:21 +08:00
|
|
|
|
}
|
2024-08-15 18:22:24 +08:00
|
|
|
|
async with ClientSession() as session:
|
|
|
|
|
async with session.get(SHOWS_API_ROOT, headers=HEADERS, params=param) as resp:
|
|
|
|
|
shows_data = await resp.json()
|
2024-07-11 18:26:21 +08:00
|
|
|
|
return shows_data
|
2024-08-15 18:22:24 +08:00
|
|
|
|
|
|
|
|
|
|
2024-07-11 18:26:21 +08:00
|
|
|
|
def process_shows_data_to_text(shows_data: dict):
|
|
|
|
|
showlist = []
|
2024-07-13 20:38:28 +08:00
|
|
|
|
data = shows_data["data"]
|
|
|
|
|
total_pages = data["numPages"]
|
|
|
|
|
result = data["result"]
|
|
|
|
|
for i in result:
|
2024-07-11 18:26:21 +08:00
|
|
|
|
name = i["project_name"]
|
|
|
|
|
venue_name = i["venue_name"]
|
|
|
|
|
project_id = i["project_id"]
|
|
|
|
|
sale_flag = i["sale_flag"]
|
2024-08-15 18:22:24 +08:00
|
|
|
|
# start_time = i["start_time"]
|
2024-08-08 20:50:18 +08:00
|
|
|
|
start_unix = i["start_unix"]
|
|
|
|
|
start_time = convert_timestamp(start_unix)
|
2024-07-11 18:26:21 +08:00
|
|
|
|
end_time = i["end_time"]
|
|
|
|
|
price_low = i["price_low"] / 100
|
|
|
|
|
price_high = i["price_high"] / 100
|
|
|
|
|
district_name = i["district_name"]
|
|
|
|
|
text = f"名称:{name}\n举办地:{venue_name}\nid:{project_id}\nflag:{sale_flag}\n开始时间:{start_time}\n结束时间:{end_time}\n最低票价:{price_low}\n最高票价:{price_high}\n区名:{district_name}\n\n"
|
|
|
|
|
showlist.append(text)
|
|
|
|
|
return showlist
|
|
|
|
|
|
2024-08-15 18:22:24 +08:00
|
|
|
|
|
2024-07-11 18:26:21 +08:00
|
|
|
|
def process_shows_data_to_template(shows_data: dict):
|
|
|
|
|
showlist = []
|
2024-07-13 20:38:28 +08:00
|
|
|
|
data = shows_data["data"]
|
|
|
|
|
page = data["page"]
|
|
|
|
|
total_pages = data["numPages"]
|
|
|
|
|
total_results = data["total"]
|
|
|
|
|
result = data["result"]
|
2024-07-11 18:26:21 +08:00
|
|
|
|
# show_template = read_template_file('/home/asankilp/LiteyukiBot/src/plugins/acgnshow/res/template.html')
|
2024-07-13 20:38:28 +08:00
|
|
|
|
for i in result:
|
2024-07-11 18:26:21 +08:00
|
|
|
|
name = i["project_name"]
|
|
|
|
|
venue_name = i["venue_name"]
|
|
|
|
|
project_id = i["project_id"]
|
|
|
|
|
sale_flag = i["sale_flag"]
|
2024-08-15 18:22:24 +08:00
|
|
|
|
# start_time = i["start_time"]
|
2024-08-08 20:50:18 +08:00
|
|
|
|
start_unix = i["start_unix"]
|
|
|
|
|
start_time = convert_timestamp(start_unix)
|
2024-07-11 18:26:21 +08:00
|
|
|
|
end_time = i["end_time"]
|
|
|
|
|
price_low = i["price_low"] / 100
|
|
|
|
|
price_high = i["price_high"] / 100
|
|
|
|
|
district_name = i["district_name"]
|
|
|
|
|
wish = i["wish"]
|
|
|
|
|
cover = "https:" + i["cover"]
|
2024-08-22 22:50:18 +08:00
|
|
|
|
if district_name == None:
|
|
|
|
|
district_name = ""
|
2024-08-08 20:50:18 +08:00
|
|
|
|
guests_list = i["guests"]
|
|
|
|
|
if guests_list != None:
|
2024-08-22 22:50:18 +08:00
|
|
|
|
guests = "、".join(n["name"] for n in guests_list)
|
|
|
|
|
else:
|
|
|
|
|
guests = ""
|
2024-07-13 20:38:28 +08:00
|
|
|
|
item_dict = {
|
2024-08-22 22:50:18 +08:00
|
|
|
|
"name": name,
|
|
|
|
|
"location": district_name + venue_name,
|
|
|
|
|
"sale_flag": sale_flag,
|
|
|
|
|
"id": project_id,
|
|
|
|
|
"price": price_low,
|
|
|
|
|
"start_time": start_time,
|
|
|
|
|
"end_time": end_time,
|
|
|
|
|
"wish": wish,
|
|
|
|
|
"image_url": cover,
|
|
|
|
|
"guests": guests,
|
|
|
|
|
"page": page,
|
|
|
|
|
"total_pages": total_pages,
|
2024-08-15 18:22:24 +08:00
|
|
|
|
}
|
2024-07-13 20:38:28 +08:00
|
|
|
|
showlist.append(item_dict)
|
|
|
|
|
global_data_dict = {
|
2024-08-22 22:50:18 +08:00
|
|
|
|
"page": page,
|
|
|
|
|
"total_pages": total_pages,
|
|
|
|
|
"total_results": total_results,
|
2024-07-13 20:38:28 +08:00
|
|
|
|
}
|
2024-08-08 20:50:18 +08:00
|
|
|
|
return [showlist, global_data_dict]
|