From 49d35ed8874f22e1d502748ae39377947dff5611 Mon Sep 17 00:00:00 2001 From: Chris Schafer Date: Thu, 14 Jul 2016 21:04:23 -0700 Subject: [PATCH 1/7] Working with pokedex program --- decode.py | 24 +++++++++++++++++++++++- ui/index.html | 1 + ui/index.js | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/decode.py b/decode.py index bf3437a..15797c2 100644 --- a/decode.py +++ b/decode.py @@ -4,7 +4,9 @@ import sys import numpy import math - +import requests +##Make a secrets.py with bearer= and endpoint= +from secrets import bearer, endpoint from mitmproxy.script import concurrent from mitmproxy.models import decoded @@ -39,8 +41,21 @@ request_api = {} #Match responses to their requests pokeLocation = {} request_location = {} +def sendToMap(t,uid,point, meta): + if bearer == "": + return + headers = {"Authorization" : "Bearer " + bearer} + data = {"type" : t, + "uid" : uid, + "location" : point.coordinates, + "meta" : meta + } + print data + r = requests.post(endpoint + "/api/push/mapobject", json = data, headers = headers) + print r.content def triangulate((LatA, LonA, DistA), (LatB, LonB, DistB), (LatC, LonC, DistC)): + #grabbed from http://gis.stackexchange.com/questions/66/trilateration-using-3-latitude-and-longitude-points-and-3-distances #using authalic sphere #if using an ellipsoid this step is slightly different #Convert geodetic Lat/Long to ECEF xyz @@ -159,6 +174,8 @@ def response(context, flow): if fort.FortType == CHECKPOINT: f = Feature(geometry=p, id=len(features), properties={"id": fort.FortId, "title": "Pokestop", "marker-color": "00007F", "marker-symbol": "town-hall"}) features.append(f) + print f.properties + sendToMap("pokestop", fort.FortId, p, f.properties) else: f = None if fort.Team == BLUE: @@ -170,11 +187,13 @@ def response(context, flow): else: f = Feature(geometry=p, id=len(features), properties={"id": fort.FortId, "title": "Neutral Gym", "marker-color": "808080", "marker-symbol": "town-hall", "marker-size": "large"}) features.append(f) + sendToMap("gym", fort.FortId, p, f.properties) for spawn in cell.SpawnPoint: p = Point((spawn.Longitude, spawn.Latitude)) f = Feature(geometry=p, id=len(features), properties={"id": len(features), "title": "spawn", "marker-color": "00FF00", "marker-symbol": "garden"}) features.append(f) + sendToMap("spawnpoint", 0, p, f.properties) for spawn in cell.DecimatedSpawnPoint: p = Point((spawn.Longitude, spawn.Latitude)) @@ -185,11 +204,13 @@ def response(context, flow): p = Point((pokemon.Longitude, pokemon.Latitude)) f = Feature(geometry=p, id=len(features), properties={"id": len(features), "TimeTillHiddenMs": pokemon.TimeTillHiddenMs, "title": "Wild %s" % Custom_PokemonName.Name(pokemon.Pokemon.PokemonId), "marker-color": "FF0000", "marker-symbol": "suitcase"}) features.append(f) + sendToMap("pokemon", pokemon.EncounterId, p, f.properties) for pokemon in cell.CatchablePokemon: p = Point((pokemon.Longitude, pokemon.Latitude)) f = Feature(geometry=p, id=len(features), properties={"id": len(features), "ExpirationTimeMs": pokemon.ExpirationTimeMs, "title": "Catchable %s" % Custom_PokemonName.Name(pokemon.PokedexTypeId), "marker-color": "000000", "marker-symbol": "circle"}) features.append(f) + sendToMap("pokemon", pokemon.EncounterId, p, f.properties) for poke in cell.NearbyPokemon: gps = request_location[env.response_id] @@ -207,6 +228,7 @@ def response(context, flow): if not math.isnan(lat) and not math.isnan(lon) : p = Point((lon, lat)) f = Feature(geometry=p, id=len(features), properties={"id": len(features), "title": "Nearby %s" % Custom_PokemonName.Name(poke.PokedexNumber), "marker-color": "FFFFFF", "marker-symbol": "dog-park"}) + sendToMap("pokemon", poke.EncounterId, p, f.properties) features.append(f) diff --git a/ui/index.html b/ui/index.html index 383e75f..7820161 100644 --- a/ui/index.html +++ b/ui/index.html @@ -27,6 +27,7 @@
+ diff --git a/ui/index.js b/ui/index.js index e15b5da..c0eb7be 100644 --- a/ui/index.js +++ b/ui/index.js @@ -84,3 +84,4 @@ function simplestyle(f, latlon) { }) }); } +$("input").click(function(){realtime.update()}) From 2ad3e478300a69f8c3f7f718fab102bc561b03b5 Mon Sep 17 00:00:00 2001 From: Chris Schafer Date: Thu, 14 Jul 2016 21:10:41 -0700 Subject: [PATCH 2/7] In case secrets is not loaded --- decode.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/decode.py b/decode.py index 15797c2..6fe3d20 100644 --- a/decode.py +++ b/decode.py @@ -6,7 +6,11 @@ import math import requests ##Make a secrets.py with bearer= and endpoint= -from secrets import bearer, endpoint +try: + from secrets import bearer, endpoint +except: + bearer = "" + endpoint = "" from mitmproxy.script import concurrent from mitmproxy.models import decoded From 2d0e2681dcb151a7ffaea69342d2586977f5723e Mon Sep 17 00:00:00 2001 From: Chris Schafer Date: Thu, 14 Jul 2016 22:44:28 -0700 Subject: [PATCH 3/7] Fixed proto --- decode.py | 1 - 1 file changed, 1 deletion(-) diff --git a/decode.py b/decode.py index 6fe3d20..922f9f5 100644 --- a/decode.py +++ b/decode.py @@ -54,7 +54,6 @@ def sendToMap(t,uid,point, meta): "location" : point.coordinates, "meta" : meta } - print data r = requests.post(endpoint + "/api/push/mapobject", json = data, headers = headers) print r.content From 575458c331f72489617aa86ab69d2a05f6f948b5 Mon Sep 17 00:00:00 2001 From: Chris Schafer Date: Fri, 15 Jul 2016 14:31:37 -0700 Subject: [PATCH 4/7] bulk uploading --- decode.py | 27 +++++++++++++++++++++------ ui/index.html | 5 +++++ ui/index.js | 1 - 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/decode.py b/decode.py index 922f9f5..35503b1 100644 --- a/decode.py +++ b/decode.py @@ -45,6 +45,19 @@ request_api = {} #Match responses to their requests pokeLocation = {} request_location = {} +def dumpToMap(dataa): + headers = {"Authorization" : "Bearer " + bearer} + print("Dumping") + r = requests.post(endpoint + "/api/push/mapobject/bulk", json = dataa, headers = headers) + print r.content +def createItem(t,uid,point, meta): + data = {"type" : t, + "uid" : uid, + "location" : point.coordinates, + "meta" : meta + } + return data + def sendToMap(t,uid,point, meta): if bearer == "": return @@ -170,6 +183,7 @@ def response(context, flow): if (key == GET_MAP_OBJECTS): features = [] + dumpa = [] for cell in mor.MapCell: for fort in cell.Fort: @@ -178,7 +192,7 @@ def response(context, flow): f = Feature(geometry=p, id=len(features), properties={"id": fort.FortId, "title": "Pokestop", "marker-color": "00007F", "marker-symbol": "town-hall"}) features.append(f) print f.properties - sendToMap("pokestop", fort.FortId, p, f.properties) + dumpa.append(createItem("pokestop", fort.FortId, p, f.properties)) else: f = None if fort.Team == BLUE: @@ -190,13 +204,13 @@ def response(context, flow): else: f = Feature(geometry=p, id=len(features), properties={"id": fort.FortId, "title": "Neutral Gym", "marker-color": "808080", "marker-symbol": "town-hall", "marker-size": "large"}) features.append(f) - sendToMap("gym", fort.FortId, p, f.properties) + dumpa.append(createItem("gym", fort.FortId, p, f.properties)) for spawn in cell.SpawnPoint: p = Point((spawn.Longitude, spawn.Latitude)) f = Feature(geometry=p, id=len(features), properties={"id": len(features), "title": "spawn", "marker-color": "00FF00", "marker-symbol": "garden"}) features.append(f) - sendToMap("spawnpoint", 0, p, f.properties) + dumpa.append(createItem("spawnpoint", 0, p, f.properties)) for spawn in cell.DecimatedSpawnPoint: p = Point((spawn.Longitude, spawn.Latitude)) @@ -207,13 +221,13 @@ def response(context, flow): p = Point((pokemon.Longitude, pokemon.Latitude)) f = Feature(geometry=p, id=len(features), properties={"id": len(features), "TimeTillHiddenMs": pokemon.TimeTillHiddenMs, "title": "Wild %s" % Custom_PokemonName.Name(pokemon.Pokemon.PokemonId), "marker-color": "FF0000", "marker-symbol": "suitcase"}) features.append(f) - sendToMap("pokemon", pokemon.EncounterId, p, f.properties) + dumpa.append(createItem("pokemon", pokemon.EncounterId, p, f.properties)) for pokemon in cell.CatchablePokemon: p = Point((pokemon.Longitude, pokemon.Latitude)) f = Feature(geometry=p, id=len(features), properties={"id": len(features), "ExpirationTimeMs": pokemon.ExpirationTimeMs, "title": "Catchable %s" % Custom_PokemonName.Name(pokemon.PokedexTypeId), "marker-color": "000000", "marker-symbol": "circle"}) features.append(f) - sendToMap("pokemon", pokemon.EncounterId, p, f.properties) + dumpa.append(createItem("pokemon", pokemon.EncounterId, p, f.properties)) for poke in cell.NearbyPokemon: gps = request_location[env.response_id] @@ -231,12 +245,13 @@ def response(context, flow): if not math.isnan(lat) and not math.isnan(lon) : p = Point((lon, lat)) f = Feature(geometry=p, id=len(features), properties={"id": len(features), "title": "Nearby %s" % Custom_PokemonName.Name(poke.PokedexNumber), "marker-color": "FFFFFF", "marker-symbol": "dog-park"}) - sendToMap("pokemon", poke.EncounterId, p, f.properties) + dumpa.append(createItem("pokemon", poke.EncounterId, p, f.properties)) features.append(f) fc = FeatureCollection(features) dump = geojson.dumps(fc, sort_keys=True) + dumpToMap(dumpa) f = open('ui/get_map_objects.json', 'w') f.write(dump) diff --git a/ui/index.html b/ui/index.html index 7820161..ef94c92 100644 --- a/ui/index.html +++ b/ui/index.html @@ -30,6 +30,11 @@ + diff --git a/ui/index.js b/ui/index.js index c0eb7be..e15b5da 100644 --- a/ui/index.js +++ b/ui/index.js @@ -84,4 +84,3 @@ function simplestyle(f, latlon) { }) }); } -$("input").click(function(){realtime.update()}) From 15e24c6201cae88aebb39c5560e7dad526c1312b Mon Sep 17 00:00:00 2001 From: Chris Schafer Date: Fri, 15 Jul 2016 14:37:17 -0700 Subject: [PATCH 5/7] using geojson point since pokedex is fixed --- decode.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/decode.py b/decode.py index 5e1f126..1668ac3 100644 --- a/decode.py +++ b/decode.py @@ -55,7 +55,7 @@ def dumpToMap(dataa): def createItem(t,uid,point, meta): data = {"type" : t, "uid" : uid, - "location" : point.coordinates, + "location" : point, "meta" : meta } return data @@ -66,7 +66,7 @@ def sendToMap(t,uid,point, meta): headers = {"Authorization" : "Bearer " + bearer} data = {"type" : t, "uid" : uid, - "location" : point.coordinates, + "location" : point, "meta" : meta } r = requests.post(endpoint + "/api/push/mapobject", json = data, headers = headers) From e1397509f87160b5c5724657f63f02e994daa92b Mon Sep 17 00:00:00 2001 From: Chris Schafer Date: Fri, 15 Jul 2016 14:40:22 -0700 Subject: [PATCH 6/7] oops, did not mean to remove that line on the merge --- ui/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/index.html b/ui/index.html index 1fe640d..77cfdd6 100644 --- a/ui/index.html +++ b/ui/index.html @@ -36,6 +36,7 @@
+ From 07f298b0728c757ff03eae074856a46db21199e4 Mon Sep 17 00:00:00 2001 From: Eric Betts Date: Fri, 15 Jul 2016 14:59:15 -0700 Subject: [PATCH 7/7] post-merge cleanup --- decode.py | 42 ++++++++++++++++-------------------------- ui/index.html | 8 -------- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/decode.py b/decode.py index 1668ac3..8eeb55c 100644 --- a/decode.py +++ b/decode.py @@ -47,30 +47,20 @@ request_api = {} #Match responses to their requests pokeLocation = {} request_location = {} -def dumpToMap(dataa): - headers = {"Authorization" : "Bearer " + bearer} - print("Dumping") - r = requests.post(endpoint + "/api/push/mapobject/bulk", json = dataa, headers = headers) - print r.content -def createItem(t,uid,point, meta): - data = {"type" : t, - "uid" : uid, - "location" : point, - "meta" : meta - } - return data - -def sendToMap(t,uid,point, meta): + +def dumpToMap(data): if bearer == "": return - headers = {"Authorization" : "Bearer " + bearer} + headers = {"Authorization" : "Bearer %s" % bearer} + r = requests.post("%s/api/push/mapobject/bulk" % endpoint, json = data, headers = headers) + +def createItem(t, uid, point, meta): data = {"type" : t, "uid" : uid, "location" : point, "meta" : meta } - r = requests.post(endpoint + "/api/push/mapobject", json = data, headers = headers) - print r.content + return data def triangulate((LatA, LonA, DistA), (LatB, LonB, DistB), (LatC, LonC, DistC)): #grabbed from http://gis.stackexchange.com/questions/66/trilateration-using-3-latitude-and-longitude-points-and-3-distances @@ -185,7 +175,7 @@ def response(context, flow): if (key == GET_MAP_OBJECTS): features = [] - dumpa = [] + bulk = [] for cell in mor.MapCell: for fort in cell.Fort: @@ -219,7 +209,7 @@ def response(context, flow): p = Point((fort.Longitude, fort.Latitude)) f = Feature(geometry=p, id=fort.FortId, properties=props) features.append(f) - dumpa.append(createItem("gym", fort.FortId, p, f.properties)) + bulk.append(createItem("gym", fort.FortId, p, f.properties)) for spawn in cell.SpawnPoint: p = Point((spawn.Longitude, spawn.Latitude)) @@ -232,7 +222,7 @@ def response(context, flow): "marker-size": "small", }) features.append(f) - dumpa.append(createItem("spawnpoint", 0, p, f.properties)) + bulk.append(createItem("spawnpoint", 0, p, f.properties)) for spawn in cell.DecimatedSpawnPoint: p = Point((spawn.Longitude, spawn.Latitude)) @@ -256,7 +246,7 @@ def response(context, flow): "marker-symbol": "suitcase" }) features.append(f) - dumpa.append(createItem("pokemon", pokemon.EncounterId, p, f.properties)) + bulk.append(createItem("pokemon", pokemon.EncounterId, p, f.properties)) for pokemon in cell.CatchablePokemon: p = Point((pokemon.Longitude, pokemon.Latitude)) @@ -269,15 +259,15 @@ def response(context, flow): "marker-symbol": "circle" }) features.append(f) - dumpa.append(createItem("pokemon", pokemon.EncounterId, p, f.properties)) + bulk.append(createItem("pokemon", pokemon.EncounterId, p, f.properties)) for poke in cell.NearbyPokemon: gps = request_location[env.response_id] if poke.EncounterId in pokeLocation: - add=True + add = True for loc in pokeLocation[poke.EncounterId]: if gps[0] == loc[0] and gps[1] == loc[1]: - add=False + add = False if add: pokeLocation[poke.EncounterId].append((gps[0], gps[1], poke.DistanceMeters/1000)) else: @@ -293,13 +283,13 @@ def response(context, flow): "marker-color": "FFFFFF", "marker-symbol": "dog-park" }) - dumpa.append(createItem("pokemon", poke.EncounterId, p, f.properties)) + bulk.append(createItem("pokemon", poke.EncounterId, p, f.properties)) features.append(f) fc = FeatureCollection(features) dump = geojson.dumps(fc, sort_keys=True) - dumpToMap(dumpa) + dumpToMap(bulk) f = open('ui/get_map_objects.json', 'w') f.write(dump) diff --git a/ui/index.html b/ui/index.html index 77cfdd6..3de28fe 100644 --- a/ui/index.html +++ b/ui/index.html @@ -37,15 +37,7 @@
- - - -