/
main.py
75 lines (68 loc) · 2.19 KB
/
main.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
from api_check import inventory_api,backup_api
import time
import xmltodict
import threading
import webpage_check
import alarm
ring = threading.Event()
ring.clear()
def nvidia_api():
while 1:
try:
r = inventory_api()
if r is not None:
#print(r.status_code)
if r.status_code >= 200 and r.status_code < 300:
r_dict = xmltodict.parse(r.text)
inventory_status = r_dict.get('inventoryStatus').get('status')
if inventory_status != 'PRODUCT_INVENTORY_OUT_OF_STOCK':
print(inventory_status)
ring.set()
# else:
# ring.clear()
time.sleep(5)
except Exception as e:
print(e)
def nvidia_backup():
while 1:
try:
r = backup_api()
if r is not None:
#print(r.status_code)
if r.status_code >= 200 and r.status_code < 300:
r_dict = r.json()
inventory_status = r_dict['products'].get('product')[0].get('inventoryStatus').get('status')
if inventory_status != 'PRODUCT_INVENTORY_OUT_OF_STOCK':
print(inventory_status)
ring.set()
# else:
# ring.clear()
time.sleep(5)
except Exception as e:
print(e)
def alarm_t():
while 1:
try:
ring.wait(None)
alarm.alarm(3)
except Exception as e:
print(e)
def bestbuy():
while 1:
try:
if webpage_check.bestbuy_sweep() or webpage_check.other_sweep():
ring.set()
else:
ring.clear()
#print("ok")
except Exception as e:
print(e)
if __name__ == "__main__":
t1 = threading.Thread(target=nvidia_backup)
t2 = threading.Thread(target=nvidia_api)
t3 = threading.Thread(target=alarm_t)
t4 = threading.Thread(target=bestbuy)
t1.start()
t2.start()
t3.start()
t4.start()