-
-
Save LostLogia4/faa297d253c61220c2f7f0c291cb367b to your computer and use it in GitHub Desktop.
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 glob | |
import sys | |
def decode(infilename): | |
with open(infilename, 'r', encoding='utf-8') as infile: | |
# Added wiki suffix and use the specified directory. | |
with open('{0}/{1}_wiki.txt'.format(directory , infilename[2:-4]), 'w', encoding='utf-8') as outfile: | |
outfile.write('{| class="wikitable"\n|+{0}\n!Speaker\n!Text\n'.format(infilename[2:-4])) | |
for line in infile.readlines(): | |
# Only extract lines that are messages. | |
# The game recognizes these as lines starting with "mess". | |
if line.split(',')[0] == "mess": | |
#Define the speaker and dialogs | |
speaker = line.split(',')[1] | |
dialog = line.split(',')[2] | |
#Convert line breaks and remove actual line breaks caused by untruncated dialogs. | |
dialog = dialog.partition('\n')[0].replace('\\n','<br>') | |
outfile.write('|-\n|{0}||{1}\n'.format(speaker, dialog)) | |
outfile.write('|}') | |
print('Outputted the dialog to {0} formatted for the Wiki (Wiki)'.format(infilename[2:-4])) | |
def main(): | |
files = glob.glob('./*.txt') | |
directory = 'processed' | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
for filename in files: | |
decode(filename) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment