pokemongo
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 sys | |
import datetime | |
import json | |
import jinja2 | |
import os | |
import operator | |
from flask_googlemaps import GoogleMaps | |
from flask_googlemaps import Map | |
lines = [] | |
with open(sys.argv[1]) as f: | |
lines = f.read().strip().split('\n') | |
center = sys.argv[2] | |
pokemon = {} | |
spawns = {} | |
pokemonsJSON = json.load(open('pokemon.json')) | |
# 29 -> 30 | |
def fix_delta(delta): | |
return int(round(delta/10.0)*10) | |
def render(tpl_path, context): | |
path, filename = os.path.split(tpl_path) | |
return jinja2.Environment( | |
loader=jinja2.FileSystemLoader(path or './') | |
).get_template(filename).render(context) | |
# 10,52.4108212665,13.3102412315,1468989590 | |
# 10,52.4108343008,13.3101272484,1468975290 | |
for line in lines: | |
poke_id, coord_lat, coord_long, despawn = line.split(',') | |
poke_id = int(poke_id) | |
map_id = "{}_{}_{}".format(poke_id, coord_lat, coord_long) | |
loc_id = "{},{}".format(coord_lat, coord_long) | |
if loc_id not in spawns: | |
spawns[loc_id] = [] | |
t = datetime.datetime.fromtimestamp(float(despawn)) | |
t = t-datetime.timedelta(minutes=14) | |
spawns[loc_id].append({'lat': coord_lat, 'long': coord_long, 'despawn': despawn, 'id': poke_id, 'time': (t.hour, t.minute, t.day)}) | |
if poke_id not in pokemon: | |
pokemon[poke_id] = {'pokemon': pokemonsJSON[poke_id-1]} | |
if map_id not in pokemon[poke_id]: | |
pokemon[poke_id][map_id] = [] | |
pokemon[poke_id][map_id].append({'lat': coord_lat, 'long': coord_long, 'despawn': despawn, 'id': poke_id, 'time': (t.hour, t.minute, t.day)}) | |
poke_spawns = {} | |
for poke_id in xrange(0,152): | |
if poke_id not in pokemon: | |
continue | |
print '\n' | |
print "#########################################################" | |
print "#{:03} {}".format(poke_id, pokemonsJSON[poke_id-1]['Name']) | |
print "#########################################################" | |
poke_spawns[poke_id] = [] | |
for map_id in (i for i in pokemon[poke_id] if i not in ['pokemon', 'spawn_at']): | |
_, coord_lat, coord_long = map_id.split('_') | |
print "\n{},{}".format(coord_lat, coord_long) | |
spawn_at = [] | |
for spawn_entry in pokemon[poke_id][map_id]: | |
t = datetime.datetime.fromtimestamp(float(spawn_entry['despawn'])) | |
t = t-datetime.timedelta(minutes=14) | |
spawn_at.append((t.hour, t.minute, t.day, "{:02}:{:02}".format(t.hour, t.minute), spawn_entry['lat'], spawn_entry['long'])) | |
spawn_entry['time'] = (t.hour, t.minute, t.day, "{:02}:{:02}".format(t.hour, t.minute), spawn_entry['lat'], spawn_entry['long']) | |
poke_spawns[poke_id] += spawn_at | |
last_time = None | |
last_day = None | |
for t in spawn_at: | |
_t = t[0]*60+t[1] | |
if last_time: | |
delta = _t-last_time | |
if delta == 1: | |
delta = 0 | |
elif delta == 29: | |
delta = 30 | |
elif delta == 31: | |
delta = 30 | |
if delta != 0: | |
print "> {:02}:{:02} | +{}".format(t[0], t[1], delta) | |
elif (last_day != t[2]): | |
print "> {:02}:{:02}".format(t[0], t[1]) | |
else: | |
print "> {:02}:{:02}".format(t[0], t[1]) | |
last_time = _t | |
last_day = t[2] | |
poke_spawns[poke_id] = list(set(poke_spawns[poke_id])) | |
poke_spawns[poke_id] = sorted(poke_spawns[poke_id], key=lambda x: x[0]*60+x[1]) | |
loc_spawns = {} | |
for loc_id in spawns: | |
print loc_id | |
spawn_at = [] | |
for spawn_entry in spawns[loc_id]: | |
t = datetime.datetime.fromtimestamp(float(spawn_entry['despawn'])) | |
t = t-datetime.timedelta(minutes=14) | |
spawn_at.append((t.hour, t.minute, spawn_entry, t.day)) | |
spawn_at = sorted(spawn_at, key=lambda x: x[0]*60+x[1]) | |
last_time = None | |
last_day = None | |
if loc_id not in loc_spawns: | |
loc_spawns[loc_id]={'spawns':[], 'occurence':{}} | |
for t in spawn_at: | |
_t = t[0]*60+t[1] | |
poke_id = "#{:03} {}".format(t[2]['id'], pokemonsJSON[t[2]['id']-1]['Name']) | |
if poke_id not in loc_spawns[loc_id]['occurence']: | |
loc_spawns[loc_id]['occurence'][poke_id] = 0 | |
loc_spawns[loc_id]['occurence'][poke_id]+=1 | |
if last_time: | |
delta = _t-last_time | |
delta = fix_delta(delta) | |
if delta != 0 or last_day != t[2]: | |
loc_spawns[loc_id]['spawns'].append({'id': t[2]['id'], 'pokemon': pokemonsJSON[t[2]['id']-1], 'delta': delta, 'hours': t[0], 'minutes': t[1], 'day': t[3], 'time': "{:02}:{:02}".format(t[0], t[1])}) | |
print "> {:02}:{:02} - #{:03} {:10} | +{}".format(t[0], t[1], t[2]['id'], pokemonsJSON[t[2]['id']-1]['Name'], delta) | |
else: | |
loc_spawns[loc_id]['spawns'].append({'id': t[2]['id'], 'pokemon': pokemonsJSON[t[2]['id']-1], 'delta': None, 'hours': t[0], 'minutes': t[1], 'day': t[3], 'time': "{:02}:{:02}".format(t[0], t[1])}) | |
print "> {:02}:{:02} - #{:03} {:10}".format(t[0], t[1], t[2]['id'], pokemonsJSON[t[2]['id']-1]['Name']) | |
last_time = _t | |
last_day = t[2] | |
loc_spawns[loc_id]['occurence'] = sorted(loc_spawns[loc_id]['occurence'].items(), key=operator.itemgetter(1))[::-1] | |
html = render('template_spawns.html', {'loc_spawns': loc_spawns, 'pokemon': pokemon, 'poke_spawns': poke_spawns, 'filename': sys.argv[1], 'center':center}) | |
with open('spawns_{}.html'.format(sys.argv[1]), 'w') as f: | |
f.write(html) | |
html = render('template_maps2.html', {'loc_spawns': loc_spawns, 'pokemon': pokemon, 'filename': sys.argv[1], 'center':center}) | |
with open('spawns_{}_all.html'.format(sys.argv[1]), 'w') as f: | |
f.write(html) | |
#GoogleMaps(app, key=GOOGLEMAPS_KEY) | |
for poke_id in range(0,152): | |
if poke_id in pokemon: | |
html = render('template_maps.html', {'spawns': pokemon[poke_id], 'poke_id': poke_id, 'pokemon':pokemonsJSON[poke_id-1], 'filename': sys.argv[1], 'center':center}) | |
with open('spawns_{}_{}.html'.format(sys.argv[1],poke_id), 'w') as f: | |
f.write(html) |
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
<!DOCTYPE html> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>45 Pokemon GO</title> | |
<link rel="shortcut icon" href="/static/favicon.ico"> | |
<link rel="stylesheet" href=""> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> | |
<script>window.jQuery || document.write('<script src="static/jquery.js">\x3C/script>')</script> | |
<script src="https://maps.googleapis.com/maps/api/js?key=ENTER_HERE_GOOGLE_MAPS_KEY" type="text/javascript"></script> | |
<style type="text/css"> | |
#fullmap { height:100%;width:100%;top:0;left:0;position:absolute;z-index:200;margin-bottom: 20px; } | |
</style> | |
<script type="text/javascript"> | |
function initialize_map() { | |
var map = new google.maps.Map(document.getElementById('fullmap'), { | |
center: new google.maps.LatLng({{center}}), | |
zoom: 14, | |
mapTypeId: google.maps.MapTypeId.ROADMAP, | |
zoomControl: true, | |
mapTypeControl: true, | |
scaleControl: true, | |
streetViewControl: false, | |
rotateControl: true, | |
fullscreenControl: true | |
}); | |
{% for loc in spawns %} | |
{% if loc not in ['pokemon', 'spawn_at'] %} | |
var marker_{{loc.replace('.','_')}} = new google.maps.Marker({ | |
position: new google.maps.LatLng({{ loc.split('_')[1] }},{{ loc.split('_')[2] }}), | |
map: map, | |
icon: "static/icons/{{poke_id}}.png" | |
}); | |
marker_{{loc.replace('.','_')}} | |
google.maps.event.addListener( | |
marker_{{loc.replace('.','_')}}, | |
'click', | |
getInfoCallback(map, "count: {% for spawn in spawns[loc] %}<br>{{spawn.time[0]}}:{{spawn.time[1]}}{% endfor %}") | |
); | |
{% endif %} | |
{% endfor %} | |
} | |
function getInfoCallback(map, content) { | |
var infowindow = new google.maps.InfoWindow({content: content}); | |
return function() { | |
infowindow.setContent(content); | |
infowindow.open(map, this); | |
}; | |
} | |
google.maps.event.addDomListener(window, 'load', initialize_map); | |
</script> | |
<div id="fullmap" class="map"></div> | |
</html> | |
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
<!DOCTYPE html> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>45 Pokemon GO</title> | |
<link rel="shortcut icon" href="/static/favicon.ico"> | |
<link rel="stylesheet" href=""> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> | |
<script>window.jQuery || document.write('<script src="static/jquery.js">\x3C/script>')</script> | |
<script src="https://maps.googleapis.com/maps/api/js?key=ENTER_HERE_GOOGLE_MAPS_KEY" type="text/javascript"></script> | |
<style type="text/css"> | |
#fullmap { height:100%;width:100%;top:0;left:0;position:absolute;z-index:200;margin-bottom: 20px; } | |
</style> | |
<script type="text/javascript"> | |
function initialize_map() { | |
var map = new google.maps.Map(document.getElementById('fullmap'), { | |
center: new google.maps.LatLng({{center}}), | |
zoom: 14, | |
mapTypeId: google.maps.MapTypeId.ROADMAP, | |
zoomControl: true, | |
mapTypeControl: true, | |
scaleControl: true, | |
streetViewControl: false, | |
rotateControl: true, | |
fullscreenControl: true | |
}); | |
{% for loc in loc_spawns %} | |
{{ loc }} | |
var marker_{{loc.replace('.','_').replace(',','_')}} = new google.maps.Marker({ | |
position: new google.maps.LatLng({{ loc }}), | |
map: map, | |
icon: "static/forts/Gym.png" | |
}); | |
google.maps.event.addListener( | |
marker_{{loc.replace('.','_').replace(',','_')}}, | |
'click', | |
getInfoCallback(map, "<b>{{ loc }}</b><table>{% for spawn in loc_spawns[loc]['spawns'] %}<td>{{ spawn.day }}. <b>{{ spawn.time }}</b>{% if spawn.delta %}<i>(+{{ spawn.delta }})</i>{% endif %}</td><td><a href='spawns_{{filename}}_{{spawn.id}}.html'>#{{ spawn.id }} <b>{{ spawn.pokemon.Name }}</b></a></td></tr>{% endfor %}</table>") | |
); | |
{% endfor %} | |
} | |
function getInfoCallback(map, content) { | |
var infowindow = new google.maps.InfoWindow({content: content}); | |
return function() { | |
infowindow.setContent(content); | |
infowindow.open(map, this); | |
}; | |
} | |
google.maps.event.addDomListener(window, 'load', initialize_map); | |
</script> | |
<div id="fullmap" class="map"></div> | |
</html> | |
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
<!doctype html> | |
<html> | |
<head> | |
<style> | |
#iframe_container { | |
width: 100%; | |
} | |
#iframe { | |
width: 100%; | |
height: 500px; | |
} | |
#nav2 { | |
float: right; | |
} | |
#nav1 { | |
float: left; | |
} | |
#nav1, #nav2 { | |
width: 49%; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>{{filename}}</h1> | |
<div id='iframe_container'> | |
<iframe id='iframe' name='iframe' src='spawns_{{filename}}_all.html'> | |
</iframe> | |
</div> | |
<div id='nav'> | |
<hr> | |
<div id='nav1'> | |
<table> | |
{% for poke_id in range(0,152) %} | |
{% if poke_id in pokemon %} | |
<tr> | |
<td> | |
<img src="static/icons/{{poke_id}}.png"> | |
</td> | |
<td colspan=2> | |
<a href='spawns_{{filename}}_{{poke_id}}.html' target='iframe'><b>#{{poke_id}} {{pokemon[poke_id].pokemon.Name}}</b></a> | |
</td> | |
<td> | |
locations: {{ (pokemon[poke_id]|length) - 1 }}<br> | |
sightings: {{ poke_spawns[poke_id]|length }} | |
</td> | |
</tr> | |
<tr> | |
<td>day</td> | |
<td>time</td> | |
<td>gps</td> | |
</tr> | |
{% for spawn in poke_spawns[poke_id] %} | |
<tr> | |
<td>{{ spawn[2] }}.</td><td><b>{{ spawn[3] }}</b></td><td>{{ spawn[4] }},{{ spawn[5] }}</td> | |
</tr> | |
{% endfor %} | |
{% endif %} | |
{% endfor %} | |
</table> | |
</div> | |
<div id='nav2'> | |
<table> | |
<tr> | |
<td> | |
<img src="static/forts/Gym.png"> | |
</td> | |
<td> | |
<a href='spawns_{{filename}}_all.html' target='iframe'><b>All spawn locations</b></a> | |
</td> | |
</tr> | |
</table> | |
<table> | |
{% for loc in loc_spawns %} | |
<tr> | |
<th colspan=4> | |
{{ loc }} | |
</th> | |
</tr> | |
<tr> | |
<td>day</td> | |
<td>time/delta</td> | |
<td>#</td> | |
<td> </td> | |
<td>name</td> | |
</tr> | |
<!-- | |
<tr> | |
<td colspan=5> | |
{% for spawn in loc_spawns[loc]['occurence'] %} | |
{{spawn[0]}} ({{spawn[1]}}), | |
{% endfor %} | |
</td> | |
</tr> | |
--> | |
</tr> | |
{% for spawn in loc_spawns[loc]['spawns'] %} | |
<tr> | |
<td> | |
{{ spawn.day }}. | |
</td> | |
<td> | |
{{ spawn.time }} | |
{% if spawn.delta %}<i>+{{ spawn.delta }}min</i> | |
{% endif %} | |
</td> | |
<td> | |
#{{ spawn.id }} | |
</td> | |
<td> | |
<img src="static/icons/{{spawn.id}}.png"> | |
</td> | |
<td> | |
{{ spawn.pokemon.Name }} | |
</td> | |
<td> | |
</td> | |
</tr> | |
{% endfor %} | |
{% endfor %} | |
</table> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requirements.txt please