Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Reaver01 committed Jul 22, 2016
2 parents 0381359 + 110dae2 commit 3f6df60
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 27 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ We use [Slack](https://slack.com) as a web chat. [Click here to join the chat!](

# To-Do:
- [ ] Google Map API key setup
- [ ] Show all objects on map
- [x] Limit the step to farm specific area for pokestops
- [ ] Pokemon transfer filter
- [ ] Drop items when bag is full
Expand Down Expand Up @@ -54,12 +55,12 @@ Install all requirements for the project using `pip install -r ./requirements.tx

### Ubuntu virtualenv install

sudo apt-get install virtualenv -y
git clone https://github.com/PokemonGoF/PokemonGo-Bot
cd PokemonGo-Bot
virtualenv .
source bin/activate
pip install -r requirements.txt
$ sudo apt-get install virtualenv -y
$ git clone https://github.com/PokemonGoF/PokemonGo-Bot
$ cd PokemonGo-Bot
$ virtualenv .
$ source bin/activate
$ pip install -r requirements.txt

### Google Maps API (Code is not done yet)

Expand All @@ -84,6 +85,7 @@ This project uses Google Maps. There's one map coupled with the project, but as
-u USERNAME, --username USERNAME Username
-p PASSWORD, --password PASSWORD Password
-l LOCATION, --location LOCATION Location (Address or 'xx.yyyy,zz.ttttt')
-lc, --use-location-cache Bot will start at last known location
-w SPEED, --walk SPEED Walk instead of teleport with given speed (meters per second max 4.16 because of walking end on 15km/h)
-m MODE, --mode MODE Set farming Mode for the bot ('all', 'poke', 'farm')
--maxstep MAX_STEP Set the steps around your initial location(DEFAULT 5 mean 25 cells around your location)
Expand Down Expand Up @@ -136,6 +138,7 @@ Bashin
tstumm
TheGoldenXY
Reaver01
rarshonsky

## Credits
### The works are based on the Pokemon Go API
Expand Down
26 changes: 19 additions & 7 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
if sys.version_info >= (2, 7, 9):
ssl._create_default_https_context = ssl._create_unverified_context

from getpass import getpass
from pokemongo_bot import PokemonGoBot
from pokemongo_bot.cell_workers.utils import print_green, print_yellow, print_red

Expand All @@ -56,9 +57,10 @@ def init_config():
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", required=required("password"))
parser.add_argument("-u", "--username", help="Username")
parser.add_argument("-p", "--password", help="Password")
parser.add_argument("-l", "--location", help="Location", required=required("location"))
parser.add_argument("-lc", "--use-location-cache", help="Bot will start at last known location", action='store_true', default=False, dest='location_cache')
parser.add_argument("-m", "--mode", help="Farming Mode", type=str, default="all")
parser.add_argument("-w", "--walk", help="Walk instead of teleport with given speed (meters per second, e.g. 2.5)", type=float, default=2.5)
parser.add_argument("-c", "--cp",help="Set CP less than to transfer(DEFAULT 100)",type=int,default=100)
Expand All @@ -69,6 +71,11 @@ def init_config():
parser.set_defaults(DEBUG=False, TEST=False)
config = parser.parse_args()

if not config.username and not 'username' in load:
config.username = raw_input("Username: ")
if not config.password and not 'password' in load:
config.password = getpass("Password: ")

# Passed in arguments shoud trump
for key in config.__dict__:
if key in load and config.__dict__[key] == None:
Expand All @@ -95,13 +102,18 @@ def main():
print_green('[x] PokemonGO Bot v1.0')
print_yellow('[x] Configuration initialized')

bot = PokemonGoBot(config)
bot.start()
try:
bot = PokemonGoBot(config)
bot.start()

print_green('[x] Starting PokemonGo Bot....')

print_green('[x] Starting PokemonGo Bot....')
while(True):
bot.take_step()

while(True):
bot.take_step()
except KeyboardInterrupt:
print_red("\n"'[x]Exiting PokemonGo Bot')
#TODO Add number of pokemon catched, pokestops visited, highest CP pokemon catched, etc.

if __name__ == '__main__':
main()
28 changes: 26 additions & 2 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,39 @@ def pokeball_inventory(self):
return balls_stock

def _set_starting_position(self):

if self.config.test:
return

if self.config.location_cache:
try:
#
# save location flag used to pull the last known location from the location.json
with open('location.json') as f:
location_json = json.load(f)

self.position = (location_json['lat'], location_json['lng'], 0.0)
self.api.set_position(*self.position)

print('')
print('[x] Last location flag used. Overriding passed in location')
print('[x] Last in-game location was set as: {}'.format(self.position))
print('')

return
except:
pass

#
# this will fail if the location.json isn't there or not valid.
# Still runs if location is set.
self.position = self._get_pos_by_name(self.config.location)
self.api.set_position(*self.position)
print('')
print(u'[x] Address found: {}'.format(self.config.location.decode('utf-8')))
print('[x] Position in-game set as: {}'.format(self.position))
print('')

if self.config.test:
return

def _get_pos_by_name(self, location_name):
geolocator = GoogleV3(api_key=self.config.gmapkey)
Expand Down
4 changes: 2 additions & 2 deletions pokemongo_bot/cell_workers/seen_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def work(self):
print('[#] Arrived at Pokestop')
sleep(2)

self.api.fort_details(fort_id=self.fort['id'], latitude=position[0], longitude=position[1])
self.api.fort_details(fort_id=self.fort['id'], latitude=lat, longitude=lng)
response_dict = self.api.call()
fort_details = response_dict['responses']['FORT_DETAILS']
fort_name = fort_details['name'].encode('utf8', 'replace')
Expand Down Expand Up @@ -71,7 +71,7 @@ def work(self):
for item_id, item_count in tmp_count_items.iteritems():
item_id = str(item_id)
item_name = self.item_list[item_id]
print_green("[+] " + str(item['item_count']) + "x " + item_name)
print_green("[+] " + str(item_count) + "x " + item_name)
else:
print_yellow("[#] Nothing found.")

Expand Down
12 changes: 3 additions & 9 deletions pokemongo_bot/stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ def take_step(self):
else:
self.api.set_position(*position)
print('[#] {}'.format(position))
with open('web/location.json', 'w') as outfile:
json.dump({'lat': position[0], 'lng': position[1]}, outfile)
if self.x == self.y or self.x < 0 and self.x == -self.y or self.x > 0 and self.x == 1 - self.y:
(self.dx, self.dy) = (-self.dy, self.dx)

Expand All @@ -73,11 +71,6 @@ def _walk_to(self, speed, lat, lng, alt):
cLng = i2f(self.api._position_lng) + dLng + random_lat_long_delta()
self.api.set_position(cLat, cLng, alt)
self.bot.heartbeat()
# Passing Variables through a file
with open('web/location.json', 'w') as outfile:
json.dump({'lat': cLat, 'lng': cLng}, outfile)


sleep(1) # sleep one second plus a random delta
self._work_at_position(i2f(self.api._position_lat), i2f(self.api._position_lng), alt, False)

Expand All @@ -89,10 +82,11 @@ def _work_at_position(self, lat, lng, alt, pokemon_only=False):
cellid = self._get_cellid(lat, lng)
timestamp = [0,] * len(cellid)
self.api.get_map_objects(latitude=f2i(lat), longitude=f2i(lng), since_timestamp_ms=timestamp, cell_id=cellid)
with open('location.json', 'w') as outfile:
json.dump({'lat': lat, 'lng': lng}, outfile)

response_dict = self.api.call()
# Passing Variables through a file
with open('web/location.json', 'w') as outfile:
json.dump({'lat': lat, 'lng': lng,'cells':response_dict['responses']['GET_MAP_OBJECTS']['map_cells']}, outfile)
if response_dict and 'responses' in response_dict and \
'GET_MAP_OBJECTS' in response_dict['responses'] and \
'status' in response_dict['responses']['GET_MAP_OBJECTS'] and \
Expand Down
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
if (success)
success(JSON.parse(xhr.responseText));
success(JSON.parse(xhr.responseText.replace(/\bNaN\b/g, "null")));
} else {
if (error)
error(xhr);
Expand Down

0 comments on commit 3f6df60

Please sign in to comment.