some-things/code/atlocation_code2geoname.py

20 lines
434 B
Python

#!/usr/bin/env python
import json
import sys
code2geoname = {}
for jsonl in open(sys.argv[1]):
rec = json.loads(jsonl)
code = [
attr['value']
for attr in rec['attributes']
if attr['predicate'] == "obo:GEO_000000023"
][0]
code2geoname[code] = rec['pid']
for jsonl in sys.stdin:
rec = json.loads(jsonl)
rec['at_location'] = code2geoname[rec['at_location']]
print(json.dumps(rec))