Fixed downloading and parsing of structures

Finish tommorow?
This commit is contained in:
2020-07-01 23:16:02 +02:00
parent 887eb37d20
commit f1f540e5da
4 changed files with 23 additions and 19 deletions

View File

@@ -1,3 +1,5 @@
from browser import window
__pragma__ ('noanno')
__pragma__ ('js', """
var fs = require('fs');
@@ -13,7 +15,7 @@ def build_structure_conversions():
global structure_conversions
structure_conversions = []
structure_conversions_raw = [line.split(",") for line in conversion_csv.split("\n")]
structure_conversions_raw = [line.split("|") for line in conversion_csv.split("\n")]
for line in structure_conversions_raw:
if min(len(line[0]), len(line[1])) == 0:
continue
@@ -22,28 +24,29 @@ def build_structure_conversions():
if line[1] == "struktura":
continue
vfrom = "^" + line[0].replace("?", "\?").replace("%s", "([a-zA-Z螚ȎŠ-]+)") + "$"
vto = line[1].replace("<struktura>", "").replace("</struktura>", "").replace("%s", "$1").strip()
vto_name = line[2].strip()
vto_id = line[4].strip()
structure_conversions.append((__new__(RegExp(vfrom, 'u')),
vto))
if 0 in (len(vto_name), len(vto_id)):
continue
vfrom = "^" + line[0].replace("?", "\?").replace("%s", "([a-zA-Z螚ȎŠ-]+)") + "$"
structure_conversions.append((__new__(RegExp(vfrom, 'u')), vto_name, vto_id))
def convert_structure(structure):
if structure_conversions is None:
build_structure_conversions()
for vfrom, vto in structure_conversions:
for vfrom, vto_name, vto_id in structure_conversions:
match = structure.match(vfrom)
if match:
# we need to remove replace alias here as we want to use javascript's one
__pragma__('noalias', 'replace')
result = structure.replace(vfrom, vto).strip()
result = structure.replace(vfrom, vto_name).strip()
__pragma__('alias', 'replace', "py_replace")
# they said this also needs to be done - remove "-d$" from %s match
if len(match) > 1 and match[1].endswith("-d"):
result = result.replace(match[1], match[1][:-2])
return result
return result, vto_id
window.console.log("Unknown structure: ", structure)
return None