Created
July 1, 2023 01:06
-
-
Save senseab/c34cf8d85b288aeffb6c8870056096e2 to your computer and use it in GitHub Desktop.
Split cheats for yuzu
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| import os | |
| import sys | |
| import re | |
| INNER=r'(?P<name>.+)\](?P<content>.+)' | |
| class Parser(): | |
| def __init__(self, cheatfile): | |
| with open(cheatfile, mode='r') as f: | |
| s = f.read() | |
| l = s.split('\n[') | |
| self.content = [] | |
| for i in l: | |
| b = self.parse(i) | |
| b['content'] = b['content'].strip('\n') | |
| b['name'] = b['name'].strip('[]') | |
| if b['content'] != '': | |
| self.content.append(b) | |
| def parse(self, block)->dict: | |
| return re.compile(INNER, re.S).match(block).groupdict() | |
| if __name__ == '__main__': | |
| filename = sys.argv[1] | |
| parser = Parser(filename) | |
| try: | |
| os.mkdir('output') | |
| except FileExistsError: | |
| pass | |
| for item in parser.content: | |
| try: | |
| os.mkdir(os.path.join('output', item['name'])) | |
| except FileExistsError: | |
| pass | |
| try: | |
| os.mkdir(os.path.join('output', item['name'], 'cheats')) | |
| except FileExistsError: | |
| pass | |
| with open(os.path.join('output', item['name'], 'cheats', filename), 'w') as f: | |
| f.write(item['content']) | |
| f.close() | |
| print('okay.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment