-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_schema.py
More file actions
42 lines (31 loc) · 1.24 KB
/
sync_schema.py
File metadata and controls
42 lines (31 loc) · 1.24 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
41
42
#!/usr/bin/env python3
"""
Sync poster_schema.json versions from the canonical poster-json-schema repository
into the VitePress public/ directory for hosting at posters.science/schema/...
Usage:
python sync_schema.py # fetch all known versions
python sync_schema.py v0.2 # fetch specific version only
"""
import json
import sys
import urllib.request
from pathlib import Path
CANONICAL_BASE = "https://raw.githubusercontent.com/fairdataihub/poster-json-schema/main"
PUBLIC_DIR = Path("public/schema")
KNOWN_VERSIONS = ["v0.1", "v0.2"]
def fetch_version(version: str) -> None:
url = f"{CANONICAL_BASE}/schemas/{version}/poster_schema.json"
dest = PUBLIC_DIR / version / "poster_schema.json"
dest.parent.mkdir(parents=True, exist_ok=True)
print(f"Fetching {url}")
with urllib.request.urlopen(url) as resp:
schema = json.loads(resp.read().decode())
with open(dest, "w", encoding="utf-8") as f:
json.dump(schema, f, indent=2, ensure_ascii=False)
f.write("\n")
print(f" -> {dest} ($id: {schema.get('$id', 'unknown')})")
if __name__ == "__main__":
versions = [sys.argv[1]] if len(sys.argv) > 1 else KNOWN_VERSIONS
for v in versions:
fetch_version(v)
print("Done.")