Skip to content

Instantly share code, notes, and snippets.

@hacknug
Last active February 25, 2017 00:09
Show Gist options
  • Save hacknug/06ad933f834a302f778de2b03b980ed3 to your computer and use it in GitHub Desktop.
Save hacknug/06ad933f834a302f778de2b03b980ed3 to your computer and use it in GitHub Desktop.
Pokémon GO GAME_MASTER Parser
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import json
import os
from collections import OrderedDict
masterNew = json.load(open('pokemongo.json'), object_pairs_hook=OrderedDict)
masterOld = json.load(open('pokemongo_old.json'), object_pairs_hook=OrderedDict)
masterNewIn = masterNew['itemTemplates']
masterOldIn = masterOld['itemTemplates']
docs = 'avatars', 'badges', 'settings', 'forms', 'items', 'types', 'quests', 'spawns', 'pokemons', 'moves', 'cameras', 'iaps', 'sequences', 'missed'
generalNew = OrderedDict()
generalOld = OrderedDict()
suffixNew = '_new'
suffixOld = '_old'
directory = 'output/'
indent = 2
if not os.path.exists(directory):
os.makedirs(directory)
def opener(document, suffix):
content = open(directory + document + suffix + '.json', 'w')
return content
def start(general):
for doc in docs:
general[doc] = {'name': doc, 'items': []}
def parse(json_file, general):
for a in json_file:
if a['templateId'].startswith('AVATAR_'):
general['avatars']['items'].append(a)
elif a['templateId'].startswith('BADGE_'):
general['badges']['items'].append(a)
elif a['templateId'].endswith('_SETTINGS'):
general['settings']['items'].append(a)
elif a['templateId'].startswith('FORMS_'):
general['forms']['items'].append(a)
elif a['templateId'].startswith('ITEM_'):
general['items']['items'].append(a)
elif a['templateId'].startswith('POKEMON_TYPE_'):
general['types']['items'].append(a)
elif a['templateId'].startswith('QUEST_'):
general['quests']['items'].append(a)
elif a['templateId'].startswith('SPAWN_'):
general['spawns']['items'].append(a)
elif a['templateId'].startswith('_MOVE_', 5):
general['moves']['items'].append(a)
elif a['templateId'].startswith('_POKEMON_', 5):
general['pokemons']['items'].append(a)
elif a['templateId'].startswith('camera_'):
general['cameras']['items'].append(a)
elif 'iapItemDisplay' in a and a['iapItemDisplay']['category'].startswith('IAP_'):
general['iaps']['items'].append(a)
elif a['templateId'].startswith('sequence_'):
general['sequences']['items'].append(a)
else:
general['missed']['items'].append(a)
print "This one fled: " + str(a)
def write(general, suffix):
for category in docs:
doc = opener(category, suffix)
for i, item in enumerate(general[category]['items']):
if i == 0:
doc.write('[' + str(json.dumps(item, indent=indent)) + ', ')
elif i == len(general[category]['items']) - 1:
doc.write(str(json.dumps(item, indent=indent)) + ']')
else:
doc.write(str(json.dumps(item, indent=indent)) + ', ')
start(generalNew)
parse(masterNewIn, generalNew)
write(generalNew, suffixNew)
start(generalOld)
parse(masterOldIn, generalOld)
write(generalOld, suffixOld)
@hacknug
Copy link
Author

hacknug commented Feb 23, 2017

It takes the GAME_MASTER json version from celandro's pokebattler-fight and splits its content in different files according to its category. I will update the gist so it checks both (current and old GAME_MASTER) to account for legacy movesets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment