1
1
"""Run this script to update the operations metadata."""
2
2
3
+ from pathlib import Path
3
4
from textwrap import dedent
4
5
5
6
import click
6
- import requests
7
7
import yaml
8
8
from tqdm import tqdm
9
9
10
- from obofoundry .constants import OPERATIONS_METADATA_PATH
11
-
12
- #: WikiData SPARQL endpoint. See https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service#Interfacing
13
- WIKIDATA_SPARQL = "https://query.wikidata.org/bigdata/namespace/wdq/sparql"
14
-
15
-
16
- def query_wikidata (query : str ):
17
- """Query the Wikidata SPARQL endpoint and return JSON."""
18
- res = requests .get (
19
- WIKIDATA_SPARQL ,
20
- params = {"query" : query , "format" : "json" },
21
- )
22
- res .raise_for_status ()
23
- res_json = res .json ()
24
- return res_json ["results" ]["bindings" ]
10
+ from obofoundry .constants import ALUMNI_METADATA_PATH , OPERATIONS_METADATA_PATH
11
+ from obofoundry .utils import query_wikidata
25
12
26
13
27
14
@click .command (name = "update-operations-metadata" )
28
15
def main ():
29
16
"""Update the operations committee members metadata file by querying Wikidata."""
30
- operations_metadata = yaml .safe_load (OPERATIONS_METADATA_PATH .read_text ())
17
+ _main (ALUMNI_METADATA_PATH )
18
+ _main (OPERATIONS_METADATA_PATH )
19
+
20
+
21
+ def _main (path : Path ):
22
+ operations_metadata = yaml .safe_load (path .read_text ())
31
23
for member in tqdm (operations_metadata ["members" ]):
32
24
orcid = member ["orcid" ]
33
25
if "wikidata" not in member or "github" not in member :
@@ -51,7 +43,7 @@ def main():
51
43
github = res [0 ].get ("github" )
52
44
if github :
53
45
member ["github" ] = github ["value" ]
54
- OPERATIONS_METADATA_PATH .write_text (
46
+ path .write_text (
55
47
yaml .safe_dump (
56
48
operations_metadata ,
57
49
sort_keys = True ,
0 commit comments