-
-
Save unilock/a1396e3b52d8ff2109b9bb7a454d315a to your computer and use it in GitHub Desktop.
Separated Leaves Python script
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
> runewood | |
1 malum:runewood_leaves | |
2 #malum:runewood_logs | |
> soulwood | |
1 malum:soulwood_leaves | |
2 #malum:soulwood_logs | |
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 os | |
# NOTE: EVERY FILE MUST HAVE TWO NEWLINES AT THE END | |
mods = ['byg', 'hexcasting', 'malum', 'regions_unexplored'] | |
for mod in mods: | |
f = open(mod + '.txt') | |
Lines = f.readlines() | |
modpath = '' | |
tree = '' | |
leaves = [] | |
logs = [] | |
completed_file = [] | |
modpath = 'data/' + mod + '/separated_leaves' | |
print('mod:', mod) | |
print('modpath:', modpath) | |
if not os.path.exists(modpath): | |
os.makedirs(modpath) | |
for line in Lines: | |
if line.startswith('>'): | |
tree = line.strip()[2:] | |
print('tree:', tree) | |
continue | |
if line.startswith('1'): | |
leaves = line.strip()[2:].split(',') | |
print('leaves:', leaves) | |
continue | |
if line.startswith('2'): | |
logs = line.strip()[2:].split(',') | |
print('logs:', logs) | |
continue | |
if line.strip() == '': | |
completed_file.append('{\n') | |
completed_file.append(' "leaves": ["' + '", "'.join(leaves) + '"],\n') | |
completed_file.append(' "logs": ["' + '", "'.join(logs) + '"]\n') | |
completed_file.append('}') | |
newfile = open(modpath + '/' + tree + '.json', 'w') | |
for line2 in completed_file: | |
newfile.write(line2) | |
newfile.close() | |
completed_file = [] | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment