114 lines
4.5 KiB
Python
114 lines
4.5 KiB
Python
import datetime
|
||
import time
|
||
|
||
import requests
|
||
|
||
import utils
|
||
|
||
|
||
def t_to_d(timestamp):
|
||
return datetime.datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
|
||
|
||
|
||
class BiliBili:
|
||
def __init__(self, cookies) -> None:
|
||
self.cookies = {k: v for k, v in (cookie.split('=') for cookie in cookies.split(';'))}
|
||
self.csrf_token = self.cookies['bili_jct']
|
||
self.headers = {
|
||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/540.36 (KHTML, like Gecko)"}
|
||
self.session = requests.Session()
|
||
|
||
def bws_info(self):
|
||
url = f"https://api.bilibili.com/x/activity/bws/online/park/reserve/info?csrf={self.csrf_token}&reserve_date=20240712,20240713,20240714"
|
||
res_info = self.session.get(url, headers=self.headers, cookies=self.cookies).json()
|
||
|
||
if res_info['code'] != 0:
|
||
print(f"cookies err: {res_info['code']} msg:{res_info['message']}")
|
||
return False
|
||
return res_info['data']
|
||
|
||
def bws_do(self, ticket_no, inter_reserve_id):
|
||
url = f"https://api.bilibili.com/x/activity/bws/online/park/reserve/do"
|
||
data = {
|
||
"ticket_no": ticket_no,
|
||
"csrf": self.csrf_token,
|
||
"inter_reserve_id": inter_reserve_id
|
||
}
|
||
res_info = self.session.post(url, headers=self.headers, cookies=self.cookies, data=data).json()
|
||
return res_info
|
||
|
||
|
||
def main():
|
||
print(
|
||
'本工具不会收集你的 log 信息,也不会上传你的任何信息。本工具仅与哔哩哔哩服务器完成交互。您清楚并知道自己所做行为,并承担后果。\n\n')
|
||
|
||
# cookie = input("请输入你的 B 站 Cookies,不会抓自己百度一下:")
|
||
cookie = utils.load()['cookie']
|
||
|
||
fuck_bw = BiliBili(cookie)
|
||
bws_info = fuck_bw.bws_info()
|
||
|
||
# err exit
|
||
if not bws_info:
|
||
print('账号信息错误或异常,请检查 网络/账号/Cookies 再试,详细报错见上方 err。')
|
||
exit()
|
||
|
||
ticket_days = list(bws_info['user_reserve_info'].keys())
|
||
ticket_id = {}
|
||
reserve_dict = {}
|
||
|
||
print("当前账号BW购票信息:")
|
||
for row in ticket_days:
|
||
ticket_id[row] = bws_info['user_ticket_info'][row]['ticket']
|
||
print(
|
||
f"{bws_info['user_ticket_info'][row]['screen_name']} | 票种:{bws_info['user_ticket_info'][row]['sku_name']} | 电子票号:{bws_info['user_ticket_info'][row]['ticket']}")
|
||
|
||
print('\n')
|
||
for row in ticket_days:
|
||
for reserve in bws_info['reserve_list'][row]:
|
||
title = reserve['act_title'].replace('\n', '')
|
||
reserve_dict[reserve['reserve_id']] = [title, reserve['act_begin_time'], reserve['reserve_begin_time']]
|
||
print(
|
||
f"活动代码:{reserve['reserve_id']} {title} 预约:{t_to_d(reserve['reserve_begin_time'])} 开始:{t_to_d(reserve['act_begin_time'])}")
|
||
print("\n")
|
||
|
||
reserve_id_list = []
|
||
|
||
in_id = input('输入活动代码(四位数字):')
|
||
# in_id = '6028' # 《UP!共创剧场 十万个冷笑话篇》先行点映+UP主见面会 预约:2024-07-09 18:05:00 开始:2024-07-13 14:15:00
|
||
# in_id = '6155' # BanG Dream! 闪光亚克力立牌 B Zero Gravity ver. 预约:2024-07-09 18:25:00 开始:2024-07-13 08:30:00
|
||
# in_id = '6154' # BanG Dream! 闪光亚克力立牌 A Zero Gravity ver. 预约:2024-07-09 18:25:00 开始:2024-07-13 08:30:00
|
||
|
||
if int(in_id) not in reserve_dict:
|
||
print('选择不正确!')
|
||
|
||
reserve_id_list.append(int(in_id))
|
||
print(f'{in_id}:{reserve_dict[int(in_id)][0]} 已选中')
|
||
print()
|
||
|
||
print('一次抢一个,如果觉得抢的少请自行多开。\n')
|
||
for i in reserve_id_list:
|
||
# 单个活动
|
||
days = datetime.datetime.fromtimestamp(reserve_dict[i][1]).strftime("%Y%m%d")
|
||
ticket_no = ticket_id[days]
|
||
inter_reserve_id = i
|
||
gap_time = 0
|
||
while True:
|
||
if int(time.time()) <= reserve_dict[i][2]:
|
||
if int(time.time()) > gap_time + 3 and gap_time + 30 < reserve_dict[i][2]:
|
||
gap_time = int(time.time())
|
||
print(
|
||
f'等待开票……当前优先预约:{reserve_dict[i][0]} | 剩余:{reserve_dict[i][2] - int(time.time())}秒')
|
||
time.sleep(0.1)
|
||
continue
|
||
|
||
res = fuck_bw.bws_do(ticket_no, inter_reserve_id)
|
||
print(f"预约结果请自行判断,你B状态码没文档:{res}")
|
||
if res["code"] == 0:
|
||
print("预约成功")
|
||
time.sleep(0.25)
|
||
|
||
|
||
if __name__ == '__main__':
|
||
main()
|