MCPcopy Index your code
hub / github.com/PokemonGoF/PokemonGo-Bot / ApiWrapper

Class ApiWrapper

pokemongo_bot/api_wrapper.py:26–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26class ApiWrapper(PGoApi, object):
27 DEVICE_ID = None
28
29 def __init__(self, config=None):
30 self.config = config
31 self.gen_device_id()
32 self.logger = logging.getLogger(__name__)
33
34 device_info = {
35 "device_id": ApiWrapper.DEVICE_ID,
36 "device_brand": 'Apple',
37 "device_model": 'iPhone',
38 "device_model_boot": 'iPhone8,2',
39 "hardware_manufacturer": 'Apple',
40 "hardware_model": 'N66AP',
41 "firmware_brand": 'iPhone OS',
42 "firmware_type": '9.3.3'
43 }
44
45 PGoApi.__init__(self, device_info=device_info)
46 if not self.config.hashkey is None:
47 PGoApi.activate_hash_server(self,self.config.hashkey)
48 # Set to default, just for CI...
49 self.actual_lat, self.actual_lng, self.actual_alt = PGoApi.get_position(self)
50 self.teleporting = False
51 self.noised_lat, self.noised_lng, self.noised_alt = self.actual_lat, self.actual_lng, self.actual_alt
52
53 self.useVanillaRequest = False
54
55 def gen_device_id(self):
56 if self.config is None or self.config.username is None:
57 ApiWrapper.DEVICE_ID = "3d65919ca1c2fc3a8e2bd7cc3f974c34"
58 return
59 file_salt = None
60 did_path = os.path.join(_base_dir, 'data', 'deviceid-%s.txt' % self.config.username)
61 if os.path.exists(did_path):
62 file_salt = open(did_path, 'r').read()
63 if self.config is not None:
64 key_string = self.config.username
65 if file_salt is not None:
66 # Config and file are set, so use those.
67 ApiWrapper.DEVICE_ID = hashlib.md5(key_string + file_salt).hexdigest()
68 else:
69 # Config is set, but file isn't, so make it.
70 rand_float = random.SystemRandom().random()
71 salt = base64.b64encode((struct.pack('!d', rand_float)))
72 ApiWrapper.DEVICE_ID = hashlib.md5(key_string + salt).hexdigest()
73 with open(did_path, "w") as text_file:
74 text_file.write("{0}".format(salt))
75 else:
76 if file_salt is not None:
77 # No config, but there's a file, use it.
78 ApiWrapper.DEVICE_ID = hashlib.md5(file_salt).hexdigest()
79 else:
80 # No config or file, so make up a reasonable default.
81 ApiWrapper.DEVICE_ID = "3d65919ca1c2fc3a8e2bd7cc3f974c34"
82
83 def create_request(self):

Calls

no outgoing calls