feat: add snapshot cache and state file I/O methods
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -539,6 +539,39 @@ class SnapshotDownloader:
|
||||
return None
|
||||
|
||||
|
||||
def load_snapshot_cache(self) -> List[Dict[str, Any]]:
|
||||
cache_file = self.output_dir / "snapshots_cache.json"
|
||||
if not cache_file.exists():
|
||||
return []
|
||||
try:
|
||||
with open(cache_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
return data if isinstance(data, list) else []
|
||||
except (json.JSONDecodeError, OSError):
|
||||
self.logger.warning("Could not read snapshot cache; starting fresh")
|
||||
return []
|
||||
|
||||
def save_snapshot_cache(self, snapshots: List[Dict[str, Any]]) -> None:
|
||||
cache_file = self.output_dir / "snapshots_cache.json"
|
||||
with open(cache_file, "w", encoding="utf-8") as f:
|
||||
json.dump(snapshots, f, indent=2, default=str)
|
||||
|
||||
def load_last_run_date(self) -> Optional[str]:
|
||||
state_file = self.output_dir / "last_run.json"
|
||||
if not state_file.exists():
|
||||
return None
|
||||
try:
|
||||
with open(state_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
return data.get("last_date_to")
|
||||
except (json.JSONDecodeError, OSError):
|
||||
return None
|
||||
|
||||
def save_last_run_date(self, date: str) -> None:
|
||||
state_file = self.output_dir / "last_run.json"
|
||||
with open(state_file, "w", encoding="utf-8") as f:
|
||||
json.dump({"last_date_to": date}, f)
|
||||
|
||||
async def generate_html_file(
|
||||
self, snapshots: List[Dict[str, Any]], date_from: str, date_to: str
|
||||
) -> Path:
|
||||
|
||||
Reference in New Issue
Block a user