Skip to content

Instantly share code, notes, and snippets.

@dolphinsue319
Created August 14, 2016 15:22
Show Gist options
  • Save dolphinsue319/070df3aa31944289c82584162a1861df to your computer and use it in GitHub Desktop.
Save dolphinsue319/070df3aa31944289c82584162a1861df to your computer and use it in GitHub Desktop.
pgoapi demo
from pgoapi import pgoapi
from s2sphere import Cell, CellId, LatLng
import time
def get_cell_ids(lat, long, radius = 10):
origin = CellId.from_lat_lng(LatLng.from_degrees(lat, long)).parent(15)
walk = [origin.id()]
right = origin.next()
left = origin.prev()
# Search around provided radius
for i in range(radius):
walk.append(right.id())
walk.append(left.id())
right = right.next()
left = left.prev()
# Return everything
return sorted(walk)
# wenShanCoffeePoi = LatLng.from_degrees(25.039902, 25.039902)
myPoi = {'lat': 25.050931, 'lon': 121.594072}
api = pgoapi.PGoApi()
api.set_position(myPoi['lat'], myPoi['lon'], 0.0)
api.login('ptc', 'anUser', 'aPassword')
# player = api.get_player()
# print(player)
cellIds = get_cell_ids(myPoi['lat'], myPoi['lon'])
currentTimestamp = 0
while True:
timestamps = [currentTimestamp, ] * len(cellIds)
mapObjects = api.get_map_objects(latitude=myPoi['lat'], longitude=myPoi['lon'], since_timestamp_ms=timestamps, cell_id=cellIds)
# print(mapObjects)
if mapObjects['responses']:
if 'status' in mapObjects['responses']['GET_MAP_OBJECTS']:
if mapObjects['responses']['GET_MAP_OBJECTS']['status'] == 1:
for map_cell in mapObjects['responses']['GET_MAP_OBJECTS']['map_cells']:
print map_cell
currentTimestamp = map_cell['current_timestamp_ms']
print currentTimestamp
time.sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment