Skip to content

Instantly share code, notes, and snippets.

@LostLogia4
Last active October 13, 2017 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LostLogia4/faa297d253c61220c2f7f0c291cb367b to your computer and use it in GitHub Desktop.
Save LostLogia4/faa297d253c61220c2f7f0c291cb367b to your computer and use it in GitHub Desktop.
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