diff options
| author | Pinapelz <yukais@pinapelz.com> | 2025-05-09 22:02:33 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2025-05-09 22:10:12 -0700 |
| commit | 8df4ae55d99438b13d0394fd865334c30f5b8a09 (patch) | |
| tree | d383e773e17413dd5e4fb3a011c5855d5d819bc5 /fileutil.py | |
| parent | 785db1be35f71347211eca76d279d700494061f2 (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 |
