[F] Fix caching failure
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
def clean_cache():
|
||||
cache_dir = Path(__file__).parent / 'data' / 'imdbapi_info'
|
||||
if not cache_dir.exists():
|
||||
print(f"Cache directory not found: {cache_dir}")
|
||||
return
|
||||
|
||||
count = 0
|
||||
for file_p in cache_dir.glob("*.json"):
|
||||
try:
|
||||
data = json.loads(file_p.read_text(encoding="utf-8"))
|
||||
if data.get("code") == "1":
|
||||
print(f"Removing invalid cache: {file_p.name}")
|
||||
file_p.unlink()
|
||||
|
||||
# Also remove the corresponding args/kwargs text file
|
||||
txt_p = file_p.with_suffix('.txt')
|
||||
if txt_p.exists():
|
||||
txt_p.unlink()
|
||||
count += 1
|
||||
except Exception as e:
|
||||
print(f"Error processing {file_p.name}: {e}")
|
||||
|
||||
print(f"Done. Removed {count} 'code=1' cache files.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
clean_cache()
|
||||
+1
-1
@@ -3,7 +3,7 @@ import urllib.request
|
||||
import urllib.parse
|
||||
from utils import with_disk_cache
|
||||
|
||||
@with_disk_cache('imdbapi_info')
|
||||
@with_disk_cache('imdbapi_info', should_cache=lambda res: res.get("code") == "0")
|
||||
def get_imdb_info(imdb_id: str) -> dict:
|
||||
"""
|
||||
Fetch IMDb info from imdbapi.dev as a fallback or replacement for M-Team.
|
||||
|
||||
Reference in New Issue
Block a user