Created
November 24, 2015 03:01
-
-
Save christophermorse/a100ec8878172cdf0717 to your computer and use it in GitHub Desktop.
Parse Keys for Latin Perseus Corpora
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os, os.path | |
import json | |
story = {} | |
count = 0 | |
info = [] | |
for dirpath, dirnames, filenames in os.walk("latin_text_perseus/"): | |
for filename in [f for f in filenames if f.endswith(".json")]: | |
with open(os.path.join(dirpath, filename), "r") as reading: | |
data = json.loads(reading.read()) | |
author = dirpath.split('/')[1] | |
try: | |
story[filename] = data['TEI.2']['teiHeader']['encodingDesc']['refsDecl'] | |
author = { "name": author, "title": filename } | |
author.update( {"encoding": story[filename]}) | |
info.append(author) | |
count += 1 | |
except: | |
story[filename] = data['TEI.2']['teiHeader']['encodingDesc'] | |
author = {"name": author, "title": filename} | |
author.update({"encoding": story[filename]}) | |
info.append(author) | |
count += 1 | |
with open("latin_key.json", 'w') as outfile: | |
json.dump(info, outfile, indent = 4, sort_keys = True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment