Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions sherlock_project/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import requests
import secrets
from pathlib import Path


MANIFEST_URL = "https://data.sherlockproject.xyz"
Expand Down Expand Up @@ -131,15 +132,27 @@ def __init__(
)

if response.status_code != 200:
raise FileNotFoundError(f"Bad response while accessing "
f"data file URL '{data_file_path}'."
)
try:
site_data = response.json()
except Exception as error:
raise ValueError(
f"Problem parsing json contents at '{data_file_path}': {error}."
)
local_fallback = Path(__file__).parent / "resources" / "data.json"
if local_fallback.exists():
print(
f"Warning: Remote data unavailable (HTTP {response.status_code}). "
"Falling back to bundled local data file."
)
with open(local_fallback, "r", encoding="utf-8") as f:
site_data = json.load(f)
else:
raise FileNotFoundError(
f"Bad response while accessing data file URL '{data_file_path}' "
f"(HTTP {response.status_code}). "
"Try updating: pip install -U sherlock-project"
)
else:
try:
site_data = response.json()
except Exception as error:
raise ValueError(
f"Problem parsing json contents at '{data_file_path}': {error}."
)

else:
# Reference is to a file.
Expand Down