def test_update_ordered(tmppath): p = tmppath / 'test' with update_ordered(p) as obj: obj['b'] = 2 obj['a'] = 1 with update_ordered(p) as obj: assert list(obj.keys()) == ['b', 'a']
def run(args): if fiona is None: # pragma: no cover raise SystemExit( 'fiona and shapely must be installed for this command') with fiona.collection( str(args.repos.path("geo", "level2-shape/level2.shp")), "r") as source: regions = [f for f in source] with update_ordered(args.repos.path("geo", "societies_tdwg.json"), indent=4) as soc_tdwg: for ds in args.repos.datasets: for soc in ds.societies: spec = soc_tdwg.get( soc.id, dict(lat=soc.Lat, lon=soc.Long, name=None, code=None)) if math.isclose(spec['lat'], soc.Lat) \ and math.isclose(spec['lon'], soc.Long) \ and spec['code']: continue region, dist = geo.match(spec['lon'], spec['lat'], regions) spec['name'] = region['properties']['REGION_NAM'] spec['code'] = str(region['properties']['TDWG_CODE']) if dist == 0: # pragma: no cover args.log.info('{0} contained in region {1}'.format( soc, spec['name'])) else: args.log.warning( 'assigning {0} to nearest region {1}, distance {2}'. format(soc, region['properties']['REGION_NAM'], dist)) soc_tdwg[soc.id] = spec
def update_gbif(self): with update_ordered(self.path('gbif.json'), indent=4) as d: api = gbif.GBIF() for ex in self.experiments: if ex.species_latin not in d: try: d[ex.species_latin] = api.species_data( ex.species_latin) except Exception as e: print(ex.species_latin) print(e) continue
def run(args): dataset = get_dataset(args) dataset.concepticon = args.concepticon.api dataset.glottolog = args.glottolog.api with_dataset(args, 'makecldf', dataset=dataset) if not dataset.cldf_dir.joinpath('sources.bib').exists(): raise ValueError('The dataset has no sources at {0}'.format( dataset.cldf_dir.joinpath('sources.bib'))) creators, contributors = dataset.get_creators_and_contributors( strict=False) def contrib(d): return { k: v for k, v in d.items() if k in {'name', 'affiliation', 'orcid', 'type'} } with jsonlib.update_ordered(dataset.dir / '.zenodo.json', indent=4) as md: md.update({ 'title': dataset.metadata.title, "access_right": "open", "keywords": sorted( set(md.get('keywords', []) + ["linguistics", "cldf:Wordlist"])), "creators": [contrib(p) for p in creators], "contributors": [contrib(p) for p in contributors], "communities": sorted(md.get('communities', []) + [{ "identifier": "lexibank" }], key=lambda i: i['identifier']), "upload_type": "dataset", }) if dataset.metadata.citation: md['description'] = "<p>Cite the source of the dataset as:</p>\n\n" \ "<blockquote>\n<p>{}</p>\n</blockquote>".format( html.escape(dataset.metadata.citation)) if dataset.metadata.zenodo_license: md['license'] = {'id': dataset.metadata.zenodo_license}