Updated the operations dashboard to include a rain outlook feature, providing users with a 7-day forecast based on site coordinates. Added latitude and longitude fields to the site form for better weather data integration. Enhanced the fuel log and site management functionalities to utilize dynamic fuel pricing based on historical data. Improved overall data handling and user experience across various dashboard components.
32 lines
1,003 B
Python
32 lines
1,003 B
Python
#!/usr/bin/env python3
|
|
"""Dump one PocketBase collection's schema to a JSON file.
|
|
|
|
A safety net to run before any script that PATCHes a collection's field
|
|
list. Reads only — it never writes to PocketBase.
|
|
|
|
Credentials come from .env.local (or the environment):
|
|
|
|
python3 scripts/pb-backup-collection.py SITES [outdir]
|
|
"""
|
|
import json
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
from pb_env import http, superuser_token
|
|
|
|
COLLECTION = sys.argv[1] if len(sys.argv) > 1 else "SITES"
|
|
OUTDIR = sys.argv[2] if len(sys.argv) > 2 else "/tmp"
|
|
|
|
TOKEN = superuser_token()
|
|
|
|
code, coll = http("GET", f"/api/collections/{COLLECTION}", token=TOKEN)
|
|
if code != 200:
|
|
sys.exit(f"could not read {COLLECTION}: {code} {coll}")
|
|
|
|
stamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
|
path = f"{OUTDIR}/{COLLECTION.lower()}-collection-{stamp}.json"
|
|
with open(path, "w") as f:
|
|
json.dump(coll, f, indent=2)
|
|
|
|
print(f" fields: {', '.join(f['name'] for f in coll.get('fields', []))}")
|
|
print(f" ✓ backup written to {path}")
|