From b09d5c894a0b902d90d291a69c5cecd67b8f78ed Mon Sep 17 00:00:00 2001 From: steffwiz Date: Sun, 24 Jul 2016 16:09:49 -0700 Subject: [PATCH 1/2] remove file exist checks to fix webview, remove gmaps api key write to html --- pokecli.py | 16 +++++++------- pokemongo_bot/__init__.py | 21 ++++++++----------- .../cell_workers/initial_transfer_worker.py | 6 ++---- pokemongo_bot/stepper.py | 21 +++++++------------ 4 files changed, 26 insertions(+), 38 deletions(-) diff --git a/pokecli.py b/pokecli.py index 07cf746c06..963b96bf20 100755 --- a/pokecli.py +++ b/pokecli.py @@ -48,6 +48,7 @@ def init_config(): parser = argparse.ArgumentParser() config_file = "config.json" release_config_json = "release_config.json" + web_dir = "web" # If config file exists, load variables from json load = {} @@ -172,15 +173,12 @@ def init_config(): with open(release_config_json) as data: config.release_config.update(json.load(data)) - web_index = 'web/index.html' - if config.gmapkey and os.path.isfile(web_index): - find_url = 'https:\/\/maps.googleapis.com\/maps\/api\/js\?key=\S*' - replace_url = "https://maps.googleapis.com/maps/api/js?key=%s&callback=initMap\"" - #Someone make this pretty! (Efficient) - with open(web_index, "r+") as sources: # r+ is read + write - lines = sources.readlines() - for line in lines: - sources.write(re.sub(r"%s" % find_url, replace_url % config.gmapkey, line)) + # create web dir if not exists + try: + os.makedirs(web_dir) + except OSError: + if not os.path.isdir(web_dir): + raise if config.evolve_all: config.evolve_all = [str(pokemon_name) for pokemon_name in config.evolve_all.split(',')] diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index d6df1a38d7..0c3acd1d8a 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import os import logging import googlemaps import json @@ -57,15 +56,14 @@ def work_on_cell(self, cell, position, include_fort_on_path): lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude'])) user_web_catchable = 'web/catchable-%s.json' % (self.config.username) - if os.path.isfile(user_web_catchable): # only write to file if it exists - for pokemon in cell['catchable_pokemons']: - with open(user_web_catchable, 'w') as outfile: - json.dump(pokemon, outfile) + for pokemon in cell['catchable_pokemons']: + with open(user_web_catchable, 'w') as outfile: + json.dump(pokemon, outfile) - if self.catch_pokemon(pokemon) == PokemonCatchWorker.NO_POKEBALLS: - break - with open(user_web_catchable, 'w') as outfile: - json.dump({}, outfile) + if self.catch_pokemon(pokemon) == PokemonCatchWorker.NO_POKEBALLS: + break + with open(user_web_catchable, 'w') as outfile: + json.dump({}, outfile) if (self.config.mode == "all" or self.config.mode == "poke" ) and 'wild_pokemons' in cell and len(cell['wild_pokemons']) > 0: @@ -237,9 +235,8 @@ def pokeball_inventory(self): 'inventory_delta']['inventory_items'] user_web_inventory = 'web/inventory-%s.json' % (self.config.username) - if os.path.isfile(user_web_inventory): - with open(user_web_inventory, 'w') as outfile: - json.dump(inventory_dict, outfile) + with open(user_web_inventory, 'w') as outfile: + json.dump(inventory_dict, outfile) # get player balls stock # ---------------------- diff --git a/pokemongo_bot/cell_workers/initial_transfer_worker.py b/pokemongo_bot/cell_workers/initial_transfer_worker.py index f09b91e07c..026e79ddaa 100644 --- a/pokemongo_bot/cell_workers/initial_transfer_worker.py +++ b/pokemongo_bot/cell_workers/initial_transfer_worker.py @@ -1,5 +1,4 @@ import json -import os from pokemongo_bot.human_behaviour import sleep from pokemongo_bot import logger @@ -51,9 +50,8 @@ def _initial_transfer_get_groups(self): 'inventory_delta']['inventory_items'] user_web_inventory = 'web/inventory-%s.json' % (self.config.username) - if os.path.isfile(user_web_inventory): - with open(user_web_inventory, 'w') as outfile: - json.dump(inventory_dict, outfile) + with open(user_web_inventory, 'w') as outfile: + json.dump(inventory_dict, outfile) for pokemon in inventory_dict: try: diff --git a/pokemongo_bot/stepper.py b/pokemongo_bot/stepper.py index fda5e63fb8..606364bb38 100644 --- a/pokemongo_bot/stepper.py +++ b/pokemongo_bot/stepper.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import os import json import time import pprint @@ -107,20 +106,16 @@ def _work_at_position(self, lat, lng, alt, pokemon_only=False): if 'map_cells' in response_dict['responses'][ 'GET_MAP_OBJECTS']: user_web_location = 'web/location-%s.json' % (self.config.username) - if os.path.isfile(user_web_location): - with open(user_web_location, 'w') as outfile: - json.dump( - {'lat': lat, - 'lng': lng, - 'cells': response_dict[ - 'responses']['GET_MAP_OBJECTS']['map_cells']}, - outfile) + with open(user_web_location, 'w') as outfile: + json.dump( + {'lat': lat, 'lng': lng, + 'cells': response_dict['responses']['GET_MAP_OBJECTS']['map_cells']}, + outfile) user_data_lastlocation = 'data/last-location-%s.json' % (self.config.username) - if os.path.isfile(user_data_lastlocation): - with open(user_data_lastlocation, 'w') as outfile: - outfile.truncate() - json.dump({'lat': lat, 'lng': lng}, outfile) + with open(user_data_lastlocation, 'w') as outfile: + outfile.truncate() + json.dump({'lat': lat, 'lng': lng}, outfile) if response_dict and 'responses' in response_dict: if 'GET_MAP_OBJECTS' in response_dict['responses']: From 27562cae174a72a44a48b47b82fb8c50ee905f67 Mon Sep 17 00:00:00 2001 From: steffwiz Date: Sun, 24 Jul 2016 23:40:10 -0700 Subject: [PATCH 2/2] re-add missing webview submodule --- .gitmodules | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitmodules b/.gitmodules index e69de29bb2..7930970692 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "origin"] + path = web + url = https://github.com/OpenPoGo/OpenPoGoWeb.git \ No newline at end of file