diff options
| author | Pinapelz <yukais@pinapelz.com> | 2025-05-09 22:02:33 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2025-05-09 22:02:33 -0700 |
| commit | 8f83d6bbc50d2fbdb1f326eb84c72673f98f1761 (patch) | |
| tree | 8c4e5d76b593d746a3b30f1038359f09f45f801d /fileutil.py | |
| parent | 0df3530fdea46e5e9b2a9136cfce11da53f8be94 (diff) | |
feat: implement uploading cached api endpoints
Diffstat (limited to 'fileutil.py')
| -rw-r--r-- | fileutil.py | 14 |
1 files changed, 14 insertions, 0 deletions
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 |
