MEGAINFRA-WEBAPP/scripts/pb-show-sites.py

22 lines
771 B
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
"""Print every site with its coordinates. Read-only.
python3 scripts/pb-show-sites.py
"""
from pb_env import http, superuser_token
TOKEN = superuser_token()
code, resp = http("GET", "/api/collections/sites/records?perPage=200", token=TOKEN)
if code != 200:
raise SystemExit(f"could not list sites: {code} {resp}")
items = resp.get("items", [])
print(f"\n{len(items)} site(s):\n")
for s in items:
lat = s.get("latitude")
lng = s.get("longitude")
where = f"{lat}, {lng}" if lat not in (None, "") and lng not in (None, "") else "— no coordinates —"
print(f" {s.get('name', '?'):<28} {s.get('project_code', ''):<10} {where}")
print(f" id={s['id']} job_start_date={s.get('job_start_date', '<field absent>')!r}")