Skip to content

Instantly share code, notes, and snippets.

@julcap
Created August 10, 2022 14:56
Show Gist options
  • Save julcap/202f20b732bca606aa5c1ba575e729a0 to your computer and use it in GitHub Desktop.
Save julcap/202f20b732bca606aa5c1ba575e729a0 to your computer and use it in GitHub Desktop.
Merge and parse WiiU key files
# Instructions
# Run: python WiiKeyMerger.py file1.txt file2.txt
import os
import sys
OUTPUT_FILE = "merged_keys.txt"
def parse_and_remove_duplicates(file1, file2):
if os.path.exists(OUTPUT_FILE):
os.remove(OUTPUT_FILE)
with open(file1, 'r') as f1, open(file2, 'r') as f2, open(OUTPUT_FILE, 'a') as result:
output = dict()
data1 = f1.read()
data2 = f2.read()
concatenated = data1 + '\n' + data2
for item in concatenated.split('\n'):
split = item.split('#')
if len(split) == 2:
hs = split[0].strip().lower()
comment = split[1].strip()
else:
hs = split[0].strip()
comment = ''
if hs not in output:
output[hs] = comment
# Sort by comments
output = dict(sorted(output.items(), key=lambda item: item[1]))
for item in output:
result.write(item + ' # ' + output[item] + '\n')
if __name__ == '__main__':
parse_and_remove_duplicates(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment