cook: More stuff
This commit is contained in:
parent
d5db6efde3
commit
b02a6849f7
7
cook.py
7
cook.py
|
@ -23,8 +23,8 @@ def progressbar(it, prefix="", size=60, out=sys.stdout): # Python3.6+
|
|||
print(f"{prefix}[{u'█'*x}{('.'*(size-x))}] {j}/{count} (Currently working on: {item}){' '*spacesToPrint}", end='\r', file=out, flush=True)
|
||||
lastItemLength = len(item)
|
||||
for i, item in enumerate(it):
|
||||
yield item
|
||||
show(i+1, item)
|
||||
yield item
|
||||
print(f"{prefix}[{u'█'*size}] {count}/{count} {' '*lastItemLength}", end='\r', file=out, flush=True)
|
||||
print("\n", flush=True, file=out)
|
||||
|
||||
|
@ -75,9 +75,8 @@ for file in progressbar(files_to_work_on, "", 40):
|
|||
continue
|
||||
source_match = re.search(f"<p.*?id=\"{match[1]}\".*?</p>", source.read())
|
||||
if source_match:
|
||||
source_match_fixed = re.sub('<p(?:(.*?)?(?:id=".*?")?)><a.*?<\/a>[\.\s ]*(.*?)<\/p>', rf'<p\1 id="{match[1]}">\2</p>', source_match.group())
|
||||
source_match_fixed = re.sub('<p (.*?)</p>', r'<p epub:type="footnote" \1</p>', source_match_fixed)
|
||||
fixed_text = re.sub(f'<a (?:(?:href=".*?#.*?")|(class=".*?")|(?:.*?))+>', fr'<a epub:type="noteref" \1 href="#{match[1]}">', text)
|
||||
source_match_fixed = re.sub('<p.*?><a.*?<\/a>[\.\s ]*(.*?)<\/p>', rf'<p epub:type="footnote" id="{match[1]}">\1</p>', source_match.group())
|
||||
fixed_text = re.sub(f'<a(?! epub:type="noteref").*?href="{match[0]}#{match[1]}".*?>', fr'<a epub:type="noteref" href="#{match[1]}">', text)
|
||||
text = re.sub(f"\n\s*</body>", f"\n{source_match_fixed}\n</body>", fixed_text)
|
||||
with open(f"work/{file}", 'w') as output:
|
||||
output.write(text)
|
||||
|
|
Loading…
Reference in a new issue