-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_schema.py
More file actions
40 lines (30 loc) · 1.2 KB
/
Copy pathsync_schema.py
File metadata and controls
40 lines (30 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
"""
Sync poster_schema.json from the canonical poster-json-schema repository.
Usage:
python sync_schema.py # fetch latest (root poster_schema.json)
python sync_schema.py v0.2 # fetch specific version
python sync_schema.py v0.1 # fetch older version
"""
import json
import sys
import urllib.request
CANONICAL_BASE = "https://raw.githubusercontent.com/fairdataihub/poster-json-schema/main"
LOCAL_PATH = "poster2json/schemas/poster_schema.json"
def sync(version: str | None = None) -> None:
if version:
url = f"{CANONICAL_BASE}/schemas/{version}/poster_schema.json"
else:
url = f"{CANONICAL_BASE}/poster_schema.json"
print(f"Fetching schema from {url}")
with urllib.request.urlopen(url) as resp:
schema = json.loads(resp.read().decode())
with open(LOCAL_PATH, "w", encoding="utf-8") as f:
json.dump(schema, f, indent=2, ensure_ascii=False)
f.write("\n")
print(f"Updated {LOCAL_PATH}")
print(f" $id: {schema.get('$id', 'unknown')}")
print(f" description: {schema.get('description', '')[:80]}...")
if __name__ == "__main__":
version = sys.argv[1] if len(sys.argv) > 1 else None
sync(version)