From 8f83d6bbc50d2fbdb1f326eb84c72673f98f1761 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Fri, 9 May 2025 22:02:33 -0700 Subject: feat: implement uploading cached api endpoints --- fileutil.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'fileutil.py') diff --git a/fileutil.py b/fileutil.py index baf62f0..bccc36d 100644 --- a/fileutil.py +++ b/fileutil.py @@ -2,6 +2,8 @@ import os.path import urllib.request import json import configparser +import requests +import hashlib def _read_file(path: str, lines=True) -> list: @@ -90,3 +92,15 @@ def load_json_file(json_file_path: str) -> dict: return json.load(file) +def compare_file_with_url(file_path, url): + try: + with open(file_path, "rb") as f: + local_hash = hashlib.md5(f.read()).hexdigest() + response = requests.get(url) + response.raise_for_status() + remote_hash = hashlib.md5(response.content).hexdigest() + print(f"HASH RESULT: {file_path} | {url} -> {local_hash == remote_hash}") + return local_hash == remote_hash + except Exception as e: + print(f"Error comparing {file_path} and {url}: {e}") + return False -- cgit v1.2.3