-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (28 loc) · 1.31 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
import requests
import time
from src.custom_logger import logger
from src.rpc import fetch_info, fetch_length, update_rp
def get_session_info(session):
return fetch_info(session), fetch_length(session)
def should_update_rp(info, length, last_info, last_length, last_time):
return info != last_info or length != last_length or (length['result']['speed'] == 1 and length['result']['time'] != last_time)
def update_and_sleep(info, length, last_info, last_length, last_time):
if should_update_rp(info, length, last_info, last_length, last_time):
update_rp(info, length)
last_info, last_length, last_time = info, length, length['result']['time']
time.sleep(10)
return last_info, last_length, last_time
def main():
try:
with requests.Session() as session:
last_info, last_length, last_time = None, None, None
while True:
info, length = get_session_info(session)
if None in (info, length):
time.sleep(10)
continue
last_info, last_length, last_time = update_and_sleep(info, length, last_info, last_length, last_time)
except KeyboardInterrupt:
logger.info("Program interrupted by user. Exiting...")
if __name__ == "__main__":
main()