Skip to content

Commit

Permalink
Added location parsing over geopy by providing an address
Browse files Browse the repository at this point in the history
  • Loading branch information
tejado committed Jul 14, 2016
1 parent ccb5614 commit eccdd56
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

## Demo

$ python2 main.py -u tejado -p 1234
$ python2 main.py --debug -u tejado -p 1234 --location "New York, Washington Square"
[!] DEBUG mode on
[!] Your given location: Washington Square, Greenwich, NY 12834, USA
[!] lat/long/alt: 43.0909305 -73.4989367 0.0
[!] login for: tejado
[+] RPC Session Token: TGT-899360-gFKDueEjBcKX4G ...
[+] Received API endpoint: https://pgorelease.nianticlabs.com/plfe/401/rpc
Expand Down
49 changes: 45 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import requests
import re
import struct
import json
import argparse
import pokemon_pb2

from datetime import datetime
from geopy.geocoders import GoogleV3
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)



API_URL = 'https://pgorelease.nianticlabs.com/plfe/rpc'
LOGIN_URL = 'https://sso.pokemon.com/sso/login?service=https%3A%2F%2Fsso.pokemon.com%2Fsso%2Foauth2.0%2FcallbackAuthorize'
LOGIN_OAUTH = 'https://sso.pokemon.com/sso/oauth2.0/accessToken'
Expand All @@ -17,10 +20,36 @@
SESSION.headers.update({'User-Agent': 'Niantic App'})
SESSION.verify = False

DEBUG = True
COORDS_LATITUDE = 0
COORDS_LONGITUDE = 0
COORDS_ALTITUDE = 0

def f2i(float):
return struct.unpack('<Q', struct.pack('<d', float))[0]

def f2h(float):
return hex(struct.unpack('<Q', struct.pack('<d', float))[0])

def h2f(hex):
return struct.unpack('<d', struct.pack('<Q', int(hex,16)))[0]

def set_location(location_name):
geolocator = GoogleV3()
loc = geolocator.geocode(location_name)

def get_gps_coords():
return (0x404aca0660000000, 0x40241f55a0000000, 0x4048000000000000)
print('[!] Your given location: {}'.format(loc.address))
print('[!] lat/long/alt: {} {} {}'.format(loc.latitude, loc.longitude, loc.altitude))
set_location_coords(loc.latitude, loc.longitude, loc.altitude)

def set_location_coords(lat, long, alt):
global COORDS_LATITUDE, COORDS_LONGITUDE, COORDS_ALTITUDE
COORDS_LATITUDE = f2i(lat)
COORDS_LONGITUDE = f2i(long)
COORDS_ALTITUDE = f2i(alt)

def get_location_coords():
return (COORDS_LATITUDE, COORDS_LONGITUDE, COORDS_ALTITUDE)

def api_req(api_endpoint, access_token, req):
try:
Expand All @@ -30,7 +59,7 @@ def api_req(api_endpoint, access_token, req):

p_req.requests.MergeFrom(req)

p_req.latitude, p_req.longitude, p_req.altitude = get_gps_coords()
p_req.latitude, p_req.longitude, p_req.altitude = get_location_coords()

p_req.unknown12 = 989
p_req.auth.provider = 'ptc'
Expand All @@ -43,7 +72,9 @@ def api_req(api_endpoint, access_token, req):
p_ret = pokemon_pb2.ResponseEnvelop()
p_ret.ParseFromString(r.content)
return p_ret
except:
except Exception,e:
if DEBUG:
print(e)
return None


Expand Down Expand Up @@ -117,8 +148,18 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--username", help="PTC Username", required=True)
parser.add_argument("-p", "--password", help="PTC Password", required=True)
parser.add_argument("-l", "--location", help="Location", required=True)
parser.add_argument("-d", "--debug", help="Debug Mode", action='store_true')
parser.set_defaults(DEBUG=True)
args = parser.parse_args()

if args.debug:
global DEBUG
DEBUG = True
print('[!] DEBUG mode on')

set_location(args.location)

access_token = login_ptc(args.username, args.password)
if access_token is None:
print('[-] Wrong username/password')
Expand Down

0 comments on commit eccdd56

Please sign in to comment.