X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/32e6c086edfca8358646c6699385c91def44159e..11da1ebe840102327816e08dd1de12fa8b75ca0f:/src/catalogue/api/tojson.py?ds=sidebyside diff --git a/src/catalogue/api/tojson.py b/src/catalogue/api/tojson.py index 633d4f6bb..f28351f68 100644 --- a/src/catalogue/api/tojson.py +++ b/src/catalogue/api/tojson.py @@ -1,3 +1,4 @@ +from collections import defaultdict import json import re from sys import argv @@ -90,6 +91,24 @@ tags = { 'ptrad': ('a', True, {'class': 'footnote footnote-ptrad'}, None, False), } +id_prefixes = { + 'pa': 'fn', + 'pe': 'fn', + 'pr': 'fn', + 'pt': 'fn', + 'ptrad': 'fn', + 'wers': 'f', + 'wers_wciety': 'f', + 'wers_cd': 'f', + 'wers_akap': 'f', + 'zastepnik_wersu': 'f', + 'wers_do_prawej': 'f', + 'wers_srodek': 'f', + 'akap': 'f', + 'akap_cd': 'f', + 'akap_dialog': 'f', +} + #tree = etree.parse(argv[1]) @@ -124,6 +143,9 @@ def toj(elem, S): if 'dlugi_cytat' not in S['stack'] and 'poezja_cyt' not in S['stack']: S['vindex'] += 1 output['visibleNumber'] = S['vindex'] + id_prefix = id_prefixes.get(elem.tag, 'i') + S['id'][id_prefix] += 1 + output['id'] = id_prefix + str(S['id'][id_prefix]) if attrs: output['attr'] = attrs.copy() if attr_map: @@ -184,6 +206,7 @@ def conv(tree): S = { 'index': 0, 'vindex': 0, + 'id': defaultdict(lambda: 0), 'stack': [], 'front1': [], 'front2': [],