Last active
February 11, 2022 10:07
-
-
Save PonteIneptique/f337756ffdf15a7a824d4a1ea8fc1118 to your computer and use it in GitHub Desktop.
Convert old segmonto files. Use `convert.py *.xml`
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
import re | |
import glob | |
import sys | |
Zone = { | |
"Main": "MainZone", | |
"DropCapital": "DropCapitalZone", | |
"RunningTitle": "RunningTitleZone", | |
"Margin": "MarginTextZone", | |
"Numbering": "NumberingZone" | |
} | |
Line = { | |
'Rubric': "RubricLine", | |
'Default': "DefaultLine" | |
} | |
regex = re.compile(r'LABEL="(\w+)"(\s+)DESCRIPTION="([ \w]+)"') | |
def replace(match): | |
label, space, desc = match.groups() | |
if desc.startswith("block type"): | |
desc = f"block type {Zone[label]}" | |
label = Zone[label] | |
#data.append(label) | |
else: | |
desc = f"line type {Line[label]}" | |
label = Line[label] | |
return f"""LABEL="{label}"{space}DESCRIPTION="{desc}\"""" | |
for file in sys.argv[1:]: | |
with open(file) as f: | |
xml = f.read() | |
xml = regex.sub(replace, xml) | |
with open(file, "w") as f: | |
f.write(xml) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment