forked from jekirl/poketrainer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
executable file
·57 lines (52 loc) · 2.3 KB
/
web.py
File metadata and controls
executable file
·57 lines (52 loc) · 2.3 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# DISCLAIMER: This
from flask import Flask, render_template
import json
import csv
from math import floor
from collections import defaultdict
import re
from pgoapi.poke_utils import *
app = Flask(__name__, template_folder="templates")
pokemon_names = json.load(open("pokemon.en.json"))
pokemon_details = {}
with open ("GAME_MASTER_POKEMON_v0_2.tsv") as tsv:
reader = csv.DictReader(tsv, delimiter='\t')
for row in reader:
family_id = re.match("HoloPokemonFamilyId.V([0-9]*).*",row["FamilyId"]).group(1)
pokemon_details[row["PkMn"]] = {
"BaseStamina": float(row["BaseStamina"]),
"BaseAttack": float(row["BaseAttack"]),
"BaseDefense": float(row["BaseDefense"]),
"family_id": family_id
}
@app.route("/<username>/pokemon")
def inventory(username):
with open("data_dumps/%s.json"%username) as f:
data = f.read()
data = json.loads(data.encode())
currency = data['GET_PLAYER']['player_data']['currencies'][1]['amount']
latlng = "%f,%f" % (data["lat"],data["lng"])
items = data['GET_INVENTORY']['inventory_delta']['inventory_items']
pokemons = []
candy = defaultdict(int)
player = {}
for item in items:
item = item['inventory_item_data']
pokemon = item.get("pokemon_data",{})
if "pokemon_id" in pokemon:
pokemon['name'] = pokemon_names[str(pokemon['pokemon_id'])]
pokemon.update(pokemon_details[str(pokemon['pokemon_id'])])
pokemon['iv'] = pokemonIVPercentage(pokemon)
pokemons.append(pokemon)
if 'player_stats' in item:
player = item['player_stats']
if "pokemon_family" in item:
filled_family = str(item['pokemon_family']['family_id']).zfill(4)
candy[filled_family] += item['pokemon_family'].get("candy",0)
pokemons = sorted(pokemons, lambda x,y: cmp(x["iv"],y["iv"]),reverse=True)
# add candy back into pokemon json
for pokemon in pokemons:
pokemon['candy'] = candy[pokemon['family_id']]
return render_template('pokemon.html', pokemons=pokemons, player=player,currency="{:,d}".format(currency), candy=candy,latlng=latlng)
if __name__ == "__main__":
app.run(host='0.0.0.0',debug=True)