"""Reporter demo script. This script demonstrates how to use DailyFileReporter with UTC+8 timezone and year/month archived log directories. It simulates a short run with start/success/error/summary notifications. Usage (PowerShell): pwsh -NoProfile -File ./scripts/reporter_demo.py or python ./scripts/reporter_demo.py """ from __future__ import annotations import random import time from pathlib import Path from databank.reporter.daily_file import DailyFileReporter from databank.core.models import RunSummary def main() -> None: """Run the reporter demo.""" rep = DailyFileReporter(log_dir=str(Path.cwd() / "logs"), timezone="utc+8") # Simulate a run spider_name = "demoSpider" seeds = ["tokenA", "tokenB", "tokenC"] rep.notify_start(spider_name, seeds) # simulate successes docs = 0 for _ in range(2): cnt = random.randint(1, 5) docs += cnt rep.notify_success(spider_name, cnt) time.sleep(0.2) # simulate an error rep.notify_error(spider_name, "Simulated network timeout") # Final summary summary = RunSummary() summary.total_docs = docs summary.per_spider[spider_name] = docs rep.notify_summary(summary) print("Reporter demo finished.") print("Logs are written under:", Path.cwd() / "logs") if __name__ == "__main__": main()