-
Notifications
You must be signed in to change notification settings - Fork 14
/
normal_request_manager.py
113 lines (82 loc) · 3.98 KB
/
normal_request_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from query_and_preserve import query_and_preserve
from query_order_and_pay import query_order_and_pay
from query_and_collect_ticket import query_and_collect_ticket
from query_and_enter_station import query_and_enter_station
from query_and_cancel import query_one_and_cancel
from atomic_queries import _login, _query_orders, _query_high_speed_ticket
from utils import random_boolean
import time
from threading import Thread
def main():
headers = {
"Cookie": "JSESSIONID=21A0370861087E0831E5D25D56BC9ABB; YsbCaptcha=BE12EE0295F548569DCC1D5B07FDBA55",
"Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmZHNlX21pY3Jvc2VydmljZSIsInJvbGVzIjpbIlJPTEVfVVNFUiJdLCJpZCI6IjRkMmE0NmM3LTcxY2ItNGNmMS1iNWJiLWI2ODQwNmQ5ZGE2ZiIsImlhdCI6MTYyNzI2MzE4NywiZXhwIjoxNjI3MjY2Nzg3fQ.xOXWi3QpTYL1OZqXaAHmpifyPc_lMX9smtOPTUveO9M",
"Content-Type": "application/json"
}
for i in range(30):
now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"now_time:{now_time}")
if i % 20 == 0:
uid, token = _login()
if uid is not None and token is not None:
headers['Authorization'] = "Bearer " + token
print(f"idx:{i}")
query_and_preserve(headers)
# 1/4 几率取消
if random_boolean() and random_boolean():
query_one_and_cancel(headers)
else:
query_order_and_pay(headers)
query_and_collect_ticket(headers)
query_and_enter_station(headers)
def main_thread():
threads = []
start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"start:{start_time}")
for i in range(5):
t = Thread(name="thread" + str(i), target=main)
time.sleep(1)
t.start()
threads.append(t)
for t in threads:
t.join()
end_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"start:{start_time} end:{end_time}")
def query_order():
headers = {
"Cookie": "JSESSIONID=21A0370861087E0831E5D25D56BC9ABB; YsbCaptcha=BE12EE0295F548569DCC1D5B07FDBA55",
"Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmZHNlX21pY3Jvc2VydmljZSIsInJvbGVzIjpbIlJPTEVfVVNFUiJdLCJpZCI6IjRkMmE0NmM3LTcxY2ItNGNmMS1iNWJiLWI2ODQwNmQ5ZGE2ZiIsImlhdCI6MTYyNzI2MzE4NywiZXhwIjoxNjI3MjY2Nzg3fQ.xOXWi3QpTYL1OZqXaAHmpifyPc_lMX9smtOPTUveO9M",
"Content-Type": "application/json"
}
uid, token = _login()
if uid is not None and token is not None:
headers['Authorization'] = "Bearer " + token
start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"start:{start_time}")
for i in range(50):
pairs = _query_orders(headers=headers, types=tuple([0, 1]), query_other=False)
print(pairs)
end_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"start:{start_time} end:{end_time}")
def query_tickets():
headers = {
"Cookie": "JSESSIONID=21A0370861087E0831E5D25D56BC9ABB; YsbCaptcha=BE12EE0295F548569DCC1D5B07FDBA55",
"Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmZHNlX21pY3Jvc2VydmljZSIsInJvbGVzIjpbIlJPTEVfVVNFUiJdLCJpZCI6IjRkMmE0NmM3LTcxY2ItNGNmMS1iNWJiLWI2ODQwNmQ5ZGE2ZiIsImlhdCI6MTYyNzI2MzE4NywiZXhwIjoxNjI3MjY2Nzg3fQ.xOXWi3QpTYL1OZqXaAHmpifyPc_lMX9smtOPTUveO9M",
"Content-Type": "application/json"
}
uid, token = _login()
if uid is not None and token is not None:
headers['Authorization'] = "Bearer " + token
date = time.strftime("%Y-%m-%d", time.localtime())
start = "Shang Hai"
end = "Su Zhou"
high_speed_place_pair = (start, end)
start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"start:{start_time}")
for i in range(50):
trip_ids = _query_high_speed_ticket(place_pair=high_speed_place_pair, headers=headers, time=date)
print(trip_ids)
end_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f"start:{start_time} end:{end_time}")
if __name__ == '__main__':
main_thread()