40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
"""Read SmartTime status or export a complete month, without starting Streamlit."""
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "stempelbot"))
|
|
|
|
from smarttime_browser import run_browser_job
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--month", type=lambda s: datetime.strptime(s, "%Y-%m"), help="Export YYYY-MM; omit for current dashboard status")
|
|
parser.add_argument("--output", type=Path, help="Write JSON to a new file (otherwise stdout)")
|
|
parser.add_argument("--artifacts", type=Path, help="Save local screenshots and sanitized HTML snapshots")
|
|
args = parser.parse_args()
|
|
if args.output and args.output.exists():
|
|
parser.error("Output already exists; choose a new file")
|
|
result = run_browser_job(
|
|
"month" if args.month else "status",
|
|
year=args.month.year if args.month else None,
|
|
month=args.month.month if args.month else None,
|
|
artifacts=args.artifacts,
|
|
)
|
|
payload = json.dumps(result, ensure_ascii=False, indent=2)
|
|
if args.output:
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
with args.output.open("x", encoding="utf-8") as stream:
|
|
stream.write(payload + "\n")
|
|
print(f"Saved {args.output}")
|
|
else:
|
|
print(payload)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|