Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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