-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
51 lines (44 loc) · 1.35 KB
/
client.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
import xmlrpc.client
import hashlib
import time
def compute(key: str, n: int):
i = 0
while True:
key2 = key + str(i)
key3 = key2.encode('ascii')
outcome = hashlib.sha256(key3).hexdigest()
checker = "0" * n
if outcome[:n] == checker:
return key2
i = i + 1
class Box:
def __init__(self,tk):
self.routes = ( "K98665",
"K67332",
"D66775")
self.box = ttk.Combobox(tk, values = self.routes)
self.box.place(x = 150, y=200)
self.button = Button(tk, text = "Buy", command=self.select).place(x = 200, y = 300)
def select(self):
value = self.box.get()
print(value)
ticket = buy_ticket(value)
if ticket != False:
messagebox.showinfo("showinfo", ticket)
def buy_ticket(route: str):
t1 = time.time()
with xmlrpc.client.ServerProxy("http://localhost:8001/") as proxy:
key,n = proxy.get_nouce(route)
key2 = compute(key,n)
with xmlrpc.client.ServerProxy("http://localhost:8002/") as proxy:
outcome = proxy.get_ticket(key2)
print(outcome)
t2 = time.time()
print(t2 - t1)
return outcome
def check_remain(route_id: str):
with xmlrpc.client.ServerProxy("http://localhost:8002/") as proxy:
remain = proxy.check_remain(route_id)
return remain
if __name__ == "__main__":
buy_ticket("K98665")