Skip to content

Commit

Permalink
Stepper fix (#1027)
Browse files Browse the repository at this point in the history
* Handling file opening errors and and updated pathes

* Removed extra blank line

* Fixed error text

* Adding nickname to contributors file
  • Loading branch information
Phil9l authored and douglascamata committed Jul 26, 2016
1 parent 3364aa3 commit f0a5a18
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@
* steffwiz
* pulgalipe
* BartKoppelmans
* phil9l
* VictorChen
39 changes: 23 additions & 16 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import os
import datetime
import json
import logging
Expand Down Expand Up @@ -28,8 +29,8 @@ def position(self):

def __init__(self, config):
self.config = config
self.pokemon_list = json.load(open('data/pokemon.json'))
self.item_list = json.load(open('data/items.json'))
self.pokemon_list = json.load(open(os.path.join('data', 'pokemon.json')))
self.item_list = json.load(open(os.path.join('data', 'items.json')))

def start(self):
self._setup_logging()
Expand Down Expand Up @@ -80,21 +81,27 @@ def update_web_location(self, cells=[], lat=None, lng=None, alt=None):
response_gym_details = self.api.call()
fort['gym_details'] = response_gym_details['responses']['GET_GYM_DETAILS']

user_web_location = 'web/location-%s.json' % (self.config.username)
# should check if file exists first but os is not imported here
user_web_location = os.path.join('web', 'location-%s.json' % (self.config.username))
# alt is unused atm but makes using *location easier
with open(user_web_location,'w') as outfile:
json.dump(
{'lat': lat,
'lng': lng,
'alt': alt,
'cells': cells
}, outfile)

user_data_lastlocation = 'data/last-location-%s.json' % (self.config.username)
with open(user_data_lastlocation, 'w') as outfile:
outfile.truncate()
json.dump({'lat': lat, 'lng': lng}, outfile)
try:
with open(user_web_location,'w') as outfile:
json.dump(
{'lat': lat,
'lng': lng,
'alt': alt,
'cells': cells
}, outfile)
except IOError as e:
logger.log('[x] Error while opening location file: %s' % e, 'red')

user_data_lastlocation = os.path.join('data', 'last-location-%s.json' % (self.config.username))
try:
with open(user_data_lastlocation, 'w') as outfile:
outfile.truncate()
json.dump({'lat': lat, 'lng': lng}, outfile)
except IOError as e:
logger.log('[x] Error while opening location file: %s' % e, 'red')


def find_close_cells(self, lat, lng):
cellid = get_cellid(lat, lng)
Expand Down

0 comments on commit f0a5a18

Please sign in to comment.