Guest User

Untitled

a guest
Aug 17th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1.  
  2. import os
  3. import sys
  4. import json
  5. import time
  6. import pprint
  7. import logging
  8. import getpass
  9. import argparse
  10.  
  11. # add directory of this file to PATH, so that the package will be found
  12. sys.path.append(os.path.dirname(os.path.realpath(__file__)))
  13.  
  14. # import Pokemon Go API lib
  15. from pgoapi import pgoapi
  16. from pgoapi import utilities as util
  17.  
  18.  
  19. log = logging.getLogger(__name__)
  20.  
  21. def init_config():
  22. parser = argparse.ArgumentParser()
  23. config_file = "config.json"
  24.  
  25. # If config file exists, load variables from json
  26. load = {}
  27. if os.path.isfile(config_file):
  28. with open(config_file) as data:
  29. load.update(json.load(data))
  30.  
  31. # Read passed in Arguments
  32. required = lambda x: not x in load
  33. parser.add_argument("-a", "--auth_service", help="Auth Service ('ptc' or 'google')",
  34. required=required("auth_service"))
  35. parser.add_argument("-u", "--username", help="Username", required=required("username"))
  36. parser.add_argument("-p", "--password", help="Password")
  37. parser.add_argument("-l", "--location", help="Location", required=required("location"))
  38. parser.add_argument("-d", "--debug", help="Debug Mode", action='store_true')
  39. parser.add_argument("-t", "--test", help="Only parse the specified location", action='store_true')
  40. parser.add_argument("-px", "--proxy", help="Specify a socks5 proxy url")
  41. parser.set_defaults(DEBUG=False, TEST=False)
  42. config = parser.parse_args()
  43.  
  44. # Passed in arguments shoud trump
  45. for key in config.__dict__:
  46. if key in load and config.__dict__[key] == None:
  47. config.__dict__[key] = str(load[key])
  48.  
  49. if config.__dict__["password"] is None:
  50. log.info("Secure Password Input (if there is no password prompt, use --password <pw>):")
  51. config.__dict__["password"] = getpass.getpass()
  52.  
  53. if config.auth_service not in ['ptc', 'google']:
  54. log.error("Invalid Auth service specified! ('ptc' or 'google')")
  55. return None
  56.  
  57. return config
  58.  
  59. def fgym():
  60.  
  61.  
  62. # instantiate pgoapi
  63. api = pgoapi.PGoApi()
  64.  
  65. startLat = 40.754546
  66. startLon = -73.995361
  67.  
  68. # set player position on the earth
  69.  
  70. #set lat and lon
  71. api.set_position(startLat, startLon, 10.0)
  72. #set login info, using ptc
  73. api.login('ptc', '***', '***')
  74.  
  75. #required, sets signature, encrypt.dll for 32bit python install, encrypt64.dll for 64bit python install
  76. api.activate_signature("encrypt64.dll")
  77.  
  78. # This gathers the cells located around your given coords
  79. cell_ids = util.get_cell_ids(startLat, startLon)
  80. # generates timestamp based on cell-ids
  81. timestamps = [0,] * len(cell_ids)
  82. # pulls in all nearby objects, pokestops, gyms etc
  83. response_dict = api.get_map_objects(latitude = startLat, longitude = startLon, since_timestamp_ms = timestamps, cell_id = cell_ids)
  84. print response_dict
  85.  
  86.  
  87. def main():
  88. # log settings
  89. # log format
  90. logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(module)10s] [%(levelname)5s] %(message)s')
  91. # log level for http request class
  92. logging.getLogger("requests").setLevel(logging.WARNING)
  93. # log level for main pgoapi class
  94. logging.getLogger("pgoapi").setLevel(logging.INFO)
  95. # log level for internal pgoapi class
  96. logging.getLogger("rpc_api").setLevel(logging.INFO)
  97.  
  98. config = init_config()
  99. if not config:
  100. return
  101.  
  102. if config.debug:
  103. logging.getLogger("requests").setLevel(logging.DEBUG)
  104. logging.getLogger("pgoapi").setLevel(logging.DEBUG)
  105. logging.getLogger("rpc_api").setLevel(logging.DEBUG)
  106.  
  107.  
  108. # instantiate pgoapi
  109. fgym()
  110. api = pgoapi.PGoApi()
  111. if config.proxy:
  112. api.set_proxy({'http': config.proxy, 'https': config.proxy})
  113.  
  114. # parse position
  115. position = util.get_pos_by_name(config.location)
  116. if not position:
  117. log.error('Your given location could not be found by name')
  118. return
  119. elif config.test:
  120. return
  121.  
  122. # set player position on the earth
  123. api.set_position(*position)
  124.  
  125. # new authentication initialitation
  126. if config.proxy:
  127. api.set_authentication(provider = config.auth_service, username = config.username, password = config.password, proxy_config = {'http': config.proxy, 'https': config.proxy})
  128. else:
  129. api.set_authentication(provider = config.auth_service, username = config.username, password = config.password)
  130.  
  131. # provide the path for your encrypt dll
  132. api.activate_signature("encrypt.dll")
  133.  
  134. # print get maps object
  135. cell_ids = util.get_cell_ids(position[0], position[1])
  136. timestamps = [0,] * len(cell_ids)
  137. response_dict = api.get_map_objects(latitude =position[0], longitude = position[1], since_timestamp_ms = timestamps, cell_id = cell_ids)
  138. print('Response dictionary (get_player): \n\r{}'.format(pprint.PrettyPrinter(indent=4).pformat(response_dict)))
  139. if __name__ == '__main__':
  140. main()
Add Comment
Please, Sign In to add comment