1 from concurrent.futures import ProcessPoolExecutor
2 from json import JSONDecodeError
3
4 import requests
5 from fake_useragent import UserAgent
6
7 s = requests.session()
8
9 HEADERS = {
10 'user-agent': UserAgent().random,
11 'Referer': 'https://www.360banke.com/xiaotu/index.html?libid=ayit&mod=Seats&code=041AnaGa1auRnB0zX4Ja1PTXr30AnaG3'
12 '&state=1&result=1&username=18112810153&openid=oMWEVxDxXuglWWyNzYo16AIE9a5c '
13 }
14
15 SEAT_TIME = '2021-08-05 '
16
17
18 def get_seat_data(mapid='830'):
19 """获取座位信息"""
20 url = 'https://www.360banke.com/xiaotu/Seatresv/RandomSeat.asp'
21 params = {
22 'libid': 'ayit',
23 'mapid': mapid,
24 'userid': '172069',
25 'number': '0.9968844038470264',
26 'starttime': SEAT_TIME + '07:00',
27 'endtime': SEAT_TIME + '22:30'
28 }
29 try:
30 response = s.get(url, headers=HEADERS, params=params)
31 return response.json()
32 except JSONDecodeError:
33 return None
34
35
36 def reserve(seatid):
37 """进行预约"""
38 url = 'https://www.360banke.com/xiaotu/Seatresv/seatorder.asp'
39 params = {
40 'number': '0.5245903096105133',
41 'userid': '172069',
42 'seatid': seatid,
43 'validtime': SEAT_TIME + '07:00',
44 'invalidtime': SEAT_TIME + '22:30'
45 }
46 try:
47 response = s.get(url, params=params, headers=HEADERS)
48 return response.json()
49 except JSONDecodeError:
50 return None
51
52
53 def main():
54 while True:
55 seat_data = get_seat_data()
56 if seat_data:
57 # 这段代码在一层没有找到座位的情况下在5层寻找
58 # if '未能找到可用的座位' in seat_data['msg']:
59 # seat_data = get_seat_data('834')
60 reserve_result = reserve(seat_data['seatid'])
61 print(seat_data['msg'])
62 if reserve_result:
63 if '预约成功' in reserve_result['ErrNote']:
64 print(reserve_result['ErrNote'].split('\n')[0])
65 print(f'您的座位在{seat_data["areatag"]},{seat_data["seatnum"]}号')
66 break
67 elif '有其他的座位预约' in reserve_result['ErrNote']:
68 print('您已预约了一个座位,如有需要请先取消预约,再重新预约!')
69 break
70
71
72 if __name__ == '__main__':
73 with ProcessPoolExecutor(max_workers=4) as p:
74 p.submit(main)