Skip to content

Commit

Permalink
Add meta info to json store
Browse files Browse the repository at this point in the history
  • Loading branch information
nossbigg committed Jun 11, 2019
1 parent c557fb4 commit bfff787
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
ABBREVIATIONS_SAVE_PATH = os.path.join(DATA_SAVE_PATH, "abbreviations.html")

JSON_STORE_PATH = os.path.join(DATA_SAVE_PATH, "ccc.json")
JSON_STORE_VERSION = '0.0.1'
7 changes: 4 additions & 3 deletions src/exporters/jsonExporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from common.config import JSON_STORE_PATH

JsonStore = namedtuple(
'JsonStore', 'toc_link_tree toc_nodes page_nodes ccc_refs')
'JsonStore', 'toc_link_tree toc_nodes page_nodes ccc_refs meta')


def exportStoreAsJson(toc_link_tree, toc_nodes_dict, page_nodes_dict, ccc_refs):
store = JsonStore(toc_link_tree, toc_nodes_dict, page_nodes_dict, ccc_refs)
def exportStoreAsJson(toc_link_tree, toc_nodes_dict, page_nodes_dict, ccc_refs, meta):
store = JsonStore(toc_link_tree, toc_nodes_dict,
page_nodes_dict, ccc_refs, meta)

json_store = simplejson.dumps(store)
with open(JSON_STORE_PATH, 'w+') as f:
Expand Down
14 changes: 14 additions & 0 deletions src/exporters/jsonMetaGenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from common.config import JSON_STORE_VERSION
from datetime import datetime
from collections import namedtuple

Meta = namedtuple('Meta', 'version created_at attribution')


def generate_store_meta():
version = JSON_STORE_VERSION
created_at = datetime.utcnow().isoformat()
attribution = ['Libreria Editrice Vaticana',
'St. Charles Borromeo Catholic Church']

return Meta(version, created_at, attribution)
6 changes: 5 additions & 1 deletion src/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from parsers.pageParser import parsePages
from parsers.abbreviationsParser import parseAbbreviations
from exporters.jsonExporter import exportStoreAsJson
from exporters.jsonMetaGenerator import generate_store_meta

toc_html = readTocFromDisk()
toc_link_tree, toc_nodes_dict = parseToc(toc_html)
Expand All @@ -16,4 +17,7 @@
pages_html_dict = readPagesFromDisk()
page_nodes_dict = parsePages(pages_html_dict)

exportStoreAsJson(toc_link_tree, toc_nodes_dict, page_nodes_dict, ccc_refs)
meta = generate_store_meta()

exportStoreAsJson(toc_link_tree, toc_nodes_dict,
page_nodes_dict, ccc_refs, meta)

0 comments on commit bfff787

Please sign in to comment.