Last active
February 16, 2019 23:11
-
-
Save huderlem/4ce0f61b1c2ee41d7d0b7831f6cb5916 to your computer and use it in GitHub Desktop.
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
# This script will convert some map json fields from integers to strings. | |
# Place this script in data/maps directory, and run it. | |
# python 3 version of the script | |
import re | |
import glob | |
for filepath in glob.iglob('./**/map.json', recursive=True): | |
with open(filepath) as file: | |
text = file.read() | |
text = re.sub(r'\"var_value\": +(\d+)', r'"var_value": "\1"', text) | |
text = re.sub(r'\"trainer_type\": +(\d+)', r'"trainer_type": "\1"', text) | |
text = re.sub(r'\"trainer_sight_or_berry_tree_id\": +(\d+)', r'"trainer_sight_or_berry_tree_id": "\1"', text) | |
with open(filepath, "w") as file: | |
file.write(text) | |
################################## | |
# python 2 version of the script # | |
################################## | |
# import re | |
# import fnmatch | |
# import os | |
# import glob | |
# 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: | |
# with open(filepath) as file: | |
# text = file.read() | |
# text = re.sub(r'\"var_value\": +(\d+)', r'"var_value": "\1"', text) | |
# text = re.sub(r'\"trainer_type\": +(\d+)', r'"trainer_type": "\1"', text) | |
# text = re.sub(r'\"trainer_sight_or_berry_tree_id\": +(\d+)', r'"trainer_sight_or_berry_tree_id": "\1"', text) | |
# with open(filepath, "w") as file: | |
# file.write(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment