Category talk:Manuals: Difference between revisions
Jump to navigation
Jump to search
(fix example project structure) |
No edit summary |
||
Line 16: | Line 16: | ||
def fix_pages(name, short_name, total_pages): | def fix_pages(name, short_name, total_pages): | ||
folder = f'{path_to_files}/{short_name}' | folder = f'{path_to_files}/{short_name}' | ||
path = pathlib.PurePath(f'{folder}/_{short_name}.txt') | path = pathlib.PurePath(f'{folder}/_{short_name}.txt') | ||
file = open(path, encoding='utf-8') | file = open(path, encoding='utf-8') | ||
text = file.read() | text = file.read() | ||
pages = re.split('\n\n\n\d\d?\d?\d?\n\n\n', text) | pages = re.split('\n\n\n\d\d?\d?\d?\n\n\n', text) | ||
page_count = len(pages) - 1 | page_count = len(pages) - 1 | ||
if page_count != total_pages: | if page_count != total_pages: | ||
print(f'{name} has the wrong number of pages!') | print(f'{name} has the wrong number of pages!') | ||
Line 32: | Line 26: | ||
print(f'Actual: {page_count}') | print(f'Actual: {page_count}') | ||
sys.exit() | sys.exit() | ||
page_number = 1 | page_number = 1 | ||
for page in pages: | for page in pages: | ||
padding = '' | padding = '' | ||
Line 63: | Line 55: | ||
# Project Structure | # Project Structure | ||
# /projects/manuals/AB/_AB.txt | # /projects/manuals/AB/_AB.txt | ||
# /projects/manuals/AB/AB_001.txt | # /projects/manuals/AB/AB_001.txt | ||
# ... | # ... | ||
# /projects/manuals/AB/AB_028.txt | # /projects/manuals/AB/AB_028.txt | ||
# /projects/manuals/RoE/_RoE.txt | # /projects/manuals/RoE/_RoE.txt | ||
# /projects/manuals/RoE/RoE_001.txt | # /projects/manuals/RoE/RoE_001.txt | ||
# ... | # ... | ||
# /projects/manuals/RoE/RoE_144.txt | # /projects/manuals/RoE/RoE_144.txt | ||
# /projects/manuals/SoD/_SoD.txt | # /projects/manuals/SoD/_SoD.txt | ||
# /projects/manuals/SoD/SoD_001.txt | # /projects/manuals/SoD/SoD_001.txt | ||
# ... | # ... | ||
# /projects/manuals/SoD/SoD_036.txt | # /projects/manuals/SoD/SoD_036.txt | ||
# /projects/manuals/Tutorial/_Tutorial.txt | # /projects/manuals/Tutorial/_Tutorial.txt | ||
# /projects/manuals/Tutorial/Tutorial_001.txt | # /projects/manuals/Tutorial/Tutorial_001.txt |
Revision as of 22:02, 7 January 2017
#!/usr/bin/env python3 import sys import re import pathlib path_to_files = '/projects/manuals' def main(): fix_pages('Restoration of Erathia', 'RoE', 144) fix_pages("Armageddon's Blade", 'AB', 28) fix_pages('Shadow of Death', 'SoD', 36) fix_pages('Tutorial', 'Tutorial', 12) def fix_pages(name, short_name, total_pages): folder = f'{path_to_files}/{short_name}' path = pathlib.PurePath(f'{folder}/_{short_name}.txt') file = open(path, encoding='utf-8') text = file.read() pages = re.split('\n\n\n\d\d?\d?\d?\n\n\n', text) page_count = len(pages) - 1 if page_count != total_pages: print(f'{name} has the wrong number of pages!') print(f'Expected: {total_pages}') print(f'Actual: {page_count}') sys.exit() page_number = 1 for page in pages: padding = '' if page_number < 10: padding = padding + '0' if page_number < 100: padding = padding + '0' page_name = f'{short_name}_{padding}{page_number}.txt' if page_number == 1: previous_page = 'TOC' else: previous_page = 'Page ' + str(page_number - 1) + '|Previous Page' if page_number == len(pages) - 1: next_page = 'TOC' else: next_page = 'Page ' + str(page_number + 1) + '|Next Page' page_path = pathlib.PurePath(f'{folder}/{page_name}') text = f'[[{name} Manual {previous_page}]]\n\n[[{name} Manual {next_page}]]\n\n\n[[File:{short_name}1_{page_number}.png|768px]]\n\n\n' category = f'\n\n\n[[Category:{name} Manual|{name} Manual {padding}{page_number}]]' page_file = open(page_path, 'w', encoding='utf-8') page_file.write(text + page + category) page_number = page_number + 1 if page_number > page_count: break if __name__ == "__main__": main() # Project Structure # /projects/manuals/AB/_AB.txt # /projects/manuals/AB/AB_001.txt # ... # /projects/manuals/AB/AB_028.txt # /projects/manuals/RoE/_RoE.txt # /projects/manuals/RoE/RoE_001.txt # ... # /projects/manuals/RoE/RoE_144.txt # /projects/manuals/SoD/_SoD.txt # /projects/manuals/SoD/SoD_001.txt # ... # /projects/manuals/SoD/SoD_036.txt # /projects/manuals/Tutorial/_Tutorial.txt # /projects/manuals/Tutorial/Tutorial_001.txt # ... # /projects/manuals/Tutorial/Tutorial_012.txt