Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example fixes #153

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions examples/pogo-optimizer/pogo-optimizer-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,49 @@
import getpass

# add directory of this file to PATH, so that the package will be found
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../.."))

# import Pokemon Go API lib
from pgoapi import pgoapi
from pgoapi import utilities as util

# other stuff
from google.protobuf.internal import encoder
from geopy.geocoders import GoogleV3
from s2sphere import Cell, CellId, LatLng
from tabulate import tabulate
from collections import defaultdict


log = logging.getLogger(__name__)

def get_pos_by_name(location_name):
geolocator = GoogleV3()
loc = geolocator.geocode(location_name, timeout=10)
if not loc:
return None

log.info('Your given location: %s', loc.address.encode('utf-8'))
log.info('lat/long/alt: %s %s %s', loc.latitude, loc.longitude, loc.altitude)

return (loc.latitude, loc.longitude, loc.altitude)

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)

def encode(cellid):
output = []
encoder._VarintEncoder()(output.append, cellid)
Expand All @@ -71,6 +101,7 @@ def init_config():
required=required("auth_service"))
parser.add_argument("-u", "--username", help="Username", required=required("username"))
parser.add_argument("-p", "--password", help="Password")
parser.add_argument("-l", "--location", help="Location", required=required("location"))
parser.add_argument("-d", "--debug", help="Debug Mode", action='store_true')
parser.add_argument("-t", "--test", help="Only parse the specified location", action='store_true')
parser.set_defaults(DEBUG=False, TEST=False)
Expand All @@ -91,6 +122,7 @@ def init_config():

return config


def main():
# log settings
# log format
Expand All @@ -111,21 +143,25 @@ def main():
logging.getLogger("pgoapi").setLevel(logging.DEBUG)
logging.getLogger("rpc_api").setLevel(logging.DEBUG)

position = get_pos_by_name(config.location)
if not position:
return

if config.test:
return

# instantiate pgoapi
api = pgoapi.PGoApi()

# provide player position on the earth
api.set_position(*position)

if not api.login(config.auth_service, config.username, config.password):
return

# get inventory call
# ----------------------
api.get_inventory()

# execute the RPC call
response_dict = api.call()
response_dict = api.get_inventory()

approot = os.path.dirname(os.path.realpath(__file__))

Expand Down
9 changes: 6 additions & 3 deletions examples/spiral_poi_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import argparse
import pprint

# add directory of this file to PATH, so that the package will be found
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))

from pgoapi import PGoApi
from pgoapi.utilities import f2i, h2f
from pgoapi import utilities as util
Expand Down Expand Up @@ -134,7 +137,7 @@ def main():
position = get_pos_by_name(config.location)
if not position:
return

if config.test:
return

Expand All @@ -153,7 +156,7 @@ def main():
# ----------------------
response_dict = api.get_player()

# apparently new dict has binary data in it, so formatting it with this method no longer works, pprint works here but there are other alternatives
# apparently new dict has binary data in it, so formatting it with this method no longer works, pprint works here but there are other alternatives
# print('Response dictionary: \n\r{}'.format(json.dumps(response_dict, indent=2)))
print('Response dictionary: \n\r{}'.format(pprint.PrettyPrinter(indent=4).pformat(response_dict)))
find_poi(api, position[0], position[1])
Expand All @@ -168,7 +171,7 @@ def find_poi(api, lat, lng):
lng = coord['lng']
api.set_position(lat, lng, 0)


#get_cellid was buggy -> replaced through get_cell_ids from pokecli
#timestamp gets computed a different way:
cell_ids = get_cell_ids(lat, lng)
Expand Down