-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathPokeBot.py
194 lines (159 loc) · 7.04 KB
/
PokeBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env python
"""
pgoapi - Pokemon Go API
Copyright (c) 2016 tjado <https://github.com/tejado>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
Author: tjado <https://github.com/tejado>
P.S. Not all of this is Tejados
"""
import os
import re
import json
import struct
import logging
import requests
import argparse
from time import sleep
from API import PGoApi
from API.utilities import f2i, h2f
from API.location import getNeighbors
from google.protobuf.internal import encoder
from geopy.geocoders import GoogleV3
from s2sphere import CellId, LatLng
log = logging.getLogger(__name__)
def get_pos_by_name(location_name):
geolocator = GoogleV3()
loc = geolocator.geocode(location_name)
#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 (12, 123, 0) # CHange this to ure long or lat or uncomment below stm if u have google geologcater api
#return (loc.latitude, loc.longitude, loc.altitude)
def get_cellid(lat, long):
origin = CellId.from_lat_lng(LatLng.from_degrees(lat, long)).parent(15)
walk = [origin.id()]
# 10 before and 10 after
next = origin.next()
prev = origin.prev()
for i in range(10):
walk.append(prev.id())
walk.append(next.id())
next = next.next()
prev = prev.prev()
return ''.join(map(encode, sorted(walk)))
def encode(cellid):
output = []
encoder._VarintEncoder()(output.append, cellid)
return ''.join(output)
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['accounts'][0].keys()
parser.add_argument("-a", "--auth_service", help="Auth Service ('ptc' or 'google')",
required=required("auth_service"))
parser.add_argument("-i", "--config_index", help="config_index", required=required("config_index"))
parser.add_argument("-u", "--username", help="Username", required=required("username"))
parser.add_argument("-p", "--password", help="Password", required=required("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("-c", "--cached", help="cached", action='store_true')
parser.add_argument("-t", "--test", help="Only parse the specified location", action='store_true')
parser.set_defaults(DEBUG=False, TEST=False,CACHED=False)
config = parser.parse_args()
load = load['accounts'][int(config.__dict__['config_index'])]
# Passed in arguments shoud trump
for key in config.__dict__:
if key in load and config.__dict__[key] == None:
config.__dict__[key] = load[key]
if config.auth_service not in ['ptc', 'google']:
log.error("Invalid Auth service specified! ('ptc' or 'google')")
return None
return config
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)
position = get_pos_by_name(config.location)
if config.test:
return
# instantiate pgoapi
api = PGoApi()
# provide player position on the earth
api.set_position(*position)
if not api.login(config.auth_service, config.username, config.password, config.cached):
return
# chain subrequests (methods) into one RPC call
# get player profile call
# ----------------------
api.get_player()
# get inventory call
# ----------------------
api.get_inventory()
# get map objects call
# ----------------------
#timestamp = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
#cellid = get_cellid(position[0], position[1])
#api.get_map_objects(latitude=f2i(position[0]), longitude=f2i(position[1]), since_timestamp_ms=timestamp, cell_id=cellid)
# spin a fort
# ----------------------
#fortid = '<your fortid>'
#lng = <your longitude>
#lat = <your latitude>
#api.fort_search(fort_id=fortid, fort_latitude=lat, fort_longitude=lng, player_latitude=f2i(position[0]), player_longitude=f2i(position[1]))
# release/transfer a pokemon and get candy for it
# ----------------------
#api.release_pokemon(pokemon_id = <your pokemonid>)
# get download settings call
# ----------------------
#api.download_settings(hash="4a2e9bc330dae60e7b74fc85b98868ab4700802e")
# execute the RPC call
response_dict = api.call()
print('Response dictionary: \n\r{}'.format(json.dumps(response_dict, indent=2)))
# r = api.get_player().call()
# print(r)
# alternative:
# api.get_player().get_inventory().get_map_objects().download_settings(hash="4a2e9bc330dae60e7b74fc85b98868ab4700802e").call()
while True:
api.main_loop()
# print("Any pokemon caught? : ", api.catch_near_pokemon())
# print(api.spin_near_fort())
# try:
# print(api.spin_near_fort())
# except Exception as e:
# print("Something went wrong: ", e)
# sleep(30)
import ipdb; ipdb.set_trace()
if __name__ == '__main__':
main()