cvlac-json 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cvlac_json/__init__.py +17 -0
- cvlac_json/__main__.py +3 -0
- cvlac_json/cli.py +79 -0
- cvlac_json/parser.py +775 -0
- cvlac_json/py.typed +0 -0
- cvlac_json/ror.py +231 -0
- cvlac_json/scienti.py +633 -0
- cvlac_json-0.1.0.dist-info/METADATA +114 -0
- cvlac_json-0.1.0.dist-info/RECORD +12 -0
- cvlac_json-0.1.0.dist-info/WHEEL +4 -0
- cvlac_json-0.1.0.dist-info/entry_points.txt +2 -0
- cvlac_json-0.1.0.dist-info/licenses/LICENSE +21 -0
cvlac_json/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""cvlac-json: turn a public CvLAC page (Minciencias, Colombia) into one JSON document.
|
|
2
|
+
|
|
3
|
+
>>> from cvlac_json import extract
|
|
4
|
+
>>> data = extract("0000026549") # downloads the page; Scienti ids if an apis.colav.co key is set
|
|
5
|
+
>>> data["profile"]["Nombre"], len(data["works"])
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
9
|
+
|
|
10
|
+
from .parser import build, extract, fetch, normalize_cod_rh
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
__version__ = version("cvlac-json")
|
|
14
|
+
except PackageNotFoundError: # running from a source tree without installing
|
|
15
|
+
__version__ = "0.0.0"
|
|
16
|
+
|
|
17
|
+
__all__ = ["__version__", "build", "extract", "fetch", "normalize_cod_rh"]
|
cvlac_json/__main__.py
ADDED
cvlac_json/cli.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Command line: ``cvlac-json COD_RH [-o OUT.json] ...``."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
from . import __version__
|
|
8
|
+
from .parser import extract, normalize_cod_rh
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def build_parser():
|
|
12
|
+
ap = argparse.ArgumentParser(
|
|
13
|
+
prog="cvlac-json",
|
|
14
|
+
description="Build a complete JSON from a researcher's public CvLAC page (Minciencias, Colombia).",
|
|
15
|
+
)
|
|
16
|
+
ap.add_argument("cod_rh", help="10-digit SCIENTI/CvLAC id (leading zeros are added if missing)")
|
|
17
|
+
ap.add_argument("-o", "--output", help="output JSON (default cvlac_<COD_RH>.json; '-' for standard output)")
|
|
18
|
+
ap.add_argument("--html", help="parse this saved page instead of downloading it")
|
|
19
|
+
ap.add_argument("--save-html", help="also save the downloaded page here")
|
|
20
|
+
ap.add_argument(
|
|
21
|
+
"--scienti",
|
|
22
|
+
choices=["auto", "full", "off"],
|
|
23
|
+
default="auto",
|
|
24
|
+
help="auto (default): add the Scienti ids of matching entries when an apis.colav.co key is available; "
|
|
25
|
+
"full: also add the Scienti records missing from the page; off: public page only",
|
|
26
|
+
)
|
|
27
|
+
ap.add_argument("--institution", help="Scienti dump (udea, univalle, uec, unaula; default: first that has the COD_RH)")
|
|
28
|
+
ap.add_argument("--model-year", help="Scienti model year (default: the latest of that institution)")
|
|
29
|
+
ap.add_argument(
|
|
30
|
+
"--apikey",
|
|
31
|
+
help="apis.colav.co key for this run, overriding $COLAV_APIKEY and ~/.config/colav/apikey "
|
|
32
|
+
'(it stays in the shell history; prefer --apikey "$(cat FILE)")',
|
|
33
|
+
)
|
|
34
|
+
ap.add_argument("--ror", choices=["auto", "off"], default="auto", help="look institutions up in the ROR API (default auto)")
|
|
35
|
+
ap.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
36
|
+
return ap
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main(argv=None):
|
|
40
|
+
a = build_parser().parse_args(argv)
|
|
41
|
+
try:
|
|
42
|
+
cod = normalize_cod_rh(a.cod_rh)
|
|
43
|
+
except ValueError as e:
|
|
44
|
+
print(f"error: {e}", file=sys.stderr)
|
|
45
|
+
return 2
|
|
46
|
+
page = None
|
|
47
|
+
if a.html:
|
|
48
|
+
with open(a.html, encoding="latin-1") as fh:
|
|
49
|
+
page = fh.read()
|
|
50
|
+
log = lambda msg: print(msg, file=sys.stderr)
|
|
51
|
+
if page is None and a.save_html:
|
|
52
|
+
from .parser import fetch
|
|
53
|
+
|
|
54
|
+
page = fetch(cod)
|
|
55
|
+
with open(a.save_html, "w", encoding="latin-1", errors="replace") as fh:
|
|
56
|
+
fh.write(page)
|
|
57
|
+
data = extract(
|
|
58
|
+
cod,
|
|
59
|
+
html=page,
|
|
60
|
+
scienti=a.scienti,
|
|
61
|
+
institution=a.institution,
|
|
62
|
+
model_year=a.model_year,
|
|
63
|
+
apikey=a.apikey,
|
|
64
|
+
ror=a.ror == "auto",
|
|
65
|
+
log=log,
|
|
66
|
+
)
|
|
67
|
+
out = a.output or f"cvlac_{cod}.json"
|
|
68
|
+
text = json.dumps(data, ensure_ascii=False, indent=1)
|
|
69
|
+
if out == "-":
|
|
70
|
+
sys.stdout.write(text + "\n")
|
|
71
|
+
else:
|
|
72
|
+
with open(out, "w", encoding="utf-8") as fh:
|
|
73
|
+
fh.write(text)
|
|
74
|
+
c = data["counts"]
|
|
75
|
+
log(
|
|
76
|
+
f"wrote {out}: {data['profile'].get('Nombre') or '?'} | works {c['works']} (endorsed {c['endorsed_works']}), "
|
|
77
|
+
f"projects {c['projects']}, events {c['events']}, other sections {len(data['sections'])}"
|
|
78
|
+
)
|
|
79
|
+
return 0
|