diff --git a/apiserver/main.py b/apiserver/main.py index 4f4eecf..96ed0c2 100644 --- a/apiserver/main.py +++ b/apiserver/main.py @@ -51,7 +51,7 @@ " ".join([STOCKS, INDICES, CRYPTOS, CURRENCIES, COMMODITIES]) ) -lastUpdatedTime = time.time() +last_updated_time = time.time() class apiHandler(http.server.BaseHTTPRequestHandler): @@ -70,13 +70,11 @@ def do_GET(self): {**crypto_status, **currency_status, **commodity_status} ) elif self.path == "/health": - if time.time() - lastUpdatedTime > 1200: + if time.time() - last_updated_time > 1200: self.send_response(500) - else: - self.send_response(200) - self.send_header("Content-type", "application/json") - self.end_headers() - return + self.send_header("Content-type", "application/json") + self.end_headers() + return else: message = {"message": "Not Found"} response = json.dumps(message) @@ -221,8 +219,8 @@ def update_status(symbols): with open(MAPPING[symbols][1], "w") as file: json.dump(MAPPING[symbols][0], file) - global lastUpdatedTime - lastUpdatedTime = time.time() + global last_updated_time + last_updated_time = time.time() if __name__ == "__main__": diff --git a/novel/main.py b/novel/main.py index fa435d0..eef1389 100644 --- a/novel/main.py +++ b/novel/main.py @@ -22,7 +22,7 @@ UNAVAILABLE_IPS = ["154.95.36.199"] -lastUpdatedTime = time.time() +last_updated_time = time.time() class HealthCheckHandler(http.server.BaseHTTPRequestHandler): @@ -46,10 +46,10 @@ def do_GET(self): response = json.dumps(filtered_titles) self.wfile.write(response.encode("utf-8")) elif self.path == "/health": - global lastUpdatedTime - global loopTime + global last_updated_time + global loop_time - if time.time() - lastUpdatedTime > loopTime: + if time.time() - last_updated_time > loop_time: self.send_response(500) else: self.send_response(200) @@ -110,18 +110,18 @@ def start_health_server(): ] i = 0 j = 0 -loopTime = len(books) * 5 * 60 -sleepInterval = loopTime / len(books) +loop_time = len(books) * 5 * 60 +sleep_interval = loop_time / len(books) titles = dict() if os.path.exists(CACHE_PATH): with open(CACHE_PATH, "r") as file: titles = json.load(file) - booknames = set(name for _, name in books) - booknames_previous = set(name + "previous" for _, name in books) + book_name = set(name for _, name in books) + book_name_previous = set(name + "previous" for _, name in books) dict_copy = titles.copy() for book in dict_copy.keys(): - if book not in booknames and book not in booknames_previous: + if book not in book_name and book not in book_name_previous: del titles[book] headers = { @@ -193,12 +193,12 @@ def get_book_title(url, proxy=None): print( f"Error occurred during iteration {index} on line {e.__traceback__.tb_lineno}" ) - time.sleep(sleepInterval) + time.sleep(sleep_interval) if index == len(proxies) - 1: raise e - lastUpdatedTime = time.time() - time.sleep(sleepInterval) + last_updated_time = time.time() + time.sleep(sleep_interval) i = (i + 1) % len(books) except Exception as e: