Skip to content

Instantly share code, notes, and snippets.

@portableant
Forked from paregorios/findit.py
Last active April 1, 2017 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save portableant/ac1c322ac3745efdb9f0614d2fba9fdd to your computer and use it in GitHub Desktop.
Save portableant/ac1c322ac3745efdb9f0614d2fba9fdd to your computer and use it in GitHub Desktop.
How to find all Pleiades URIs that correspond to a Trismegistos place URI
# read in the json and get the graph of places
import json
import urllib.request, urllib.parse, urllib.error
import gzip
import os
latest = "http://atlantides.org/downloads/pleiades/json/pleiades-places-latest.json.gz"
fn = os.path.join(os.getcwd(), os.path.basename(latest))
urllib.request.urlretrieve(latest, fn)
print("Downloaded latest places")
places = gzip.open(fn, mode='rb')
places = places.read()
with open(places, 'r', encoding='utf-8') as f:
pj = json.load(f)
graph = pj['@graph']
# iterate through the graph and test each place for a TM reference
for place in graph:
references = place['references']
tm_geoids = [r['accessURI'] for r in references if 'trismegistos' in r['accessURI']]
if len(tm_geoids) == 1:
print('{} = {}'.format(place['uri'], tm_geoids[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment