Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import json
- import time
- import pprint
- import logging
- import getpass
- import argparse
- # add directory of this file to PATH, so that the package will be found
- sys.path.append(os.path.dirname(os.path.realpath(__file__)))
- # import Pokemon Go API lib
- from pgoapi import pgoapi
- from pgoapi import utilities as util
- log = logging.getLogger(__name__)
- def init_config():
- parser = argparse.ArgumentParser()
- config_file = "config.json"
- # If config file exists, load variables from json
- load = {}
- if os.path.isfile(config_file):
- with open(config_file) as data:
- load.update(json.load(data))
- # Read passed in Arguments
- required = lambda x: not x in load
- parser.add_argument("-a", "--auth_service", help="Auth Service ('ptc' or 'google')",
- 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.add_argument("-px", "--proxy", help="Specify a socks5 proxy url")
- parser.set_defaults(DEBUG=False, TEST=False)
- config = parser.parse_args()
- # Passed in arguments shoud trump
- for key in config.__dict__:
- if key in load and config.__dict__[key] == None:
- config.__dict__[key] = str(load[key])
- if config.__dict__["password"] is None:
- log.info("Secure Password Input (if there is no password prompt, use --password <pw>):")
- config.__dict__["password"] = getpass.getpass()
- if config.auth_service not in ['ptc', 'google']:
- log.error("Invalid Auth service specified! ('ptc' or 'google')")
- return None
- return config
- def fgym():
- # instantiate pgoapi
- api = pgoapi.PGoApi()
- startLat = 40.754546
- startLon = -73.995361
- # set player position on the earth
- #set lat and lon
- api.set_position(startLat, startLon, 10.0)
- #set login info, using ptc
- api.login('ptc', '***', '***')
- #required, sets signature, encrypt.dll for 32bit python install, encrypt64.dll for 64bit python install
- api.activate_signature("encrypt64.dll")
- # This gathers the cells located around your given coords
- cell_ids = util.get_cell_ids(startLat, startLon)
- # generates timestamp based on cell-ids
- timestamps = [0,] * len(cell_ids)
- # pulls in all nearby objects, pokestops, gyms etc
- response_dict = api.get_map_objects(latitude = startLat, longitude = startLon, since_timestamp_ms = timestamps, cell_id = cell_ids)
- print response_dict
- def main():
- # log settings
- # log format
- logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(module)10s] [%(levelname)5s] %(message)s')
- # log level for http request class
- logging.getLogger("requests").setLevel(logging.WARNING)
- # log level for main pgoapi class
- logging.getLogger("pgoapi").setLevel(logging.INFO)
- # log level for internal pgoapi class
- logging.getLogger("rpc_api").setLevel(logging.INFO)
- config = init_config()
- if not config:
- return
- if config.debug:
- logging.getLogger("requests").setLevel(logging.DEBUG)
- logging.getLogger("pgoapi").setLevel(logging.DEBUG)
- logging.getLogger("rpc_api").setLevel(logging.DEBUG)
- # instantiate pgoapi
- fgym()
- api = pgoapi.PGoApi()
- if config.proxy:
- api.set_proxy({'http': config.proxy, 'https': config.proxy})
- # parse position
- position = util.get_pos_by_name(config.location)
- if not position:
- log.error('Your given location could not be found by name')
- return
- elif config.test:
- return
- # set player position on the earth
- api.set_position(*position)
- # new authentication initialitation
- if config.proxy:
- api.set_authentication(provider = config.auth_service, username = config.username, password = config.password, proxy_config = {'http': config.proxy, 'https': config.proxy})
- else:
- api.set_authentication(provider = config.auth_service, username = config.username, password = config.password)
- # provide the path for your encrypt dll
- api.activate_signature("encrypt.dll")
- # print get maps object
- cell_ids = util.get_cell_ids(position[0], position[1])
- timestamps = [0,] * len(cell_ids)
- response_dict = api.get_map_objects(latitude =position[0], longitude = position[1], since_timestamp_ms = timestamps, cell_id = cell_ids)
- print('Response dictionary (get_player): \n\r{}'.format(pprint.PrettyPrinter(indent=4).pformat(response_dict)))
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment