forked from Sierraffinity/CrystalDust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapadder.py
33 lines (27 loc) · 940 Bytes
/
mapadder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import re
import sys
import json
from collections import OrderedDict
import fnmatch
import glob
def main():
matches = []
for root, dirnames, filenames in os.walk('data/maps'):
for filename in fnmatch.filter(filenames, 'map.json'):
matches.append(os.path.join(root, filename))
for filepath in matches:
print("Processing %s..." % filepath)
with open(filepath) as file:
text = file.read()
modified = text.splitlines()
offset = 1 # insert after line
for index, line in enumerate(text.splitlines()):
if 'trainer_type' in line:
modified.insert(index + offset, '%s"type": "original",' % ((line.count(' ') - 1) * " "))
offset += 1
with open(filepath, "w", newline='\n') as file:
file.writelines('\n'.join(modified))
file.write('\n')
if __name__ == '__main__':
main()