Skip to content

Commit

Permalink
Removal of location from this example
Browse files Browse the repository at this point in the history
This example doesn't need to access any location information for it to work. removed (hopefully) all references to getting/setting location.
  • Loading branch information
stolencatkarma authored Jul 26, 2016
1 parent bfa96ba commit 59d63b9
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions examples/pogo-optimizer/pogo-optimizer-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,11 @@

# 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 @@ -101,7 +71,6 @@ 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 @@ -122,7 +91,6 @@ def init_config():

return config


def main():
# log settings
# log format
Expand All @@ -143,19 +111,12 @@ 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

Expand Down

0 comments on commit 59d63b9

Please sign in to comment.