From 909c367e099f4d2b0b5b321abc10e87bf7fdae21 Mon Sep 17 00:00:00 2001 From: Dmitry Ovodov Date: Thu, 25 Aug 2016 12:59:15 +0300 Subject: [PATCH] Fix No such file or directory caused by 32f0c5d2969debd2b0b2ba1ebaa0ca6eec49fa0c --- pokemongo_bot/inventory.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index 0577b65e20..fa2483687d 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1092,29 +1092,32 @@ def refresh(self): inventory = inventory['responses']['GET_INVENTORY']['inventory_delta']['inventory_items'] for i in (self.pokedex, self.candy, self.items, self.pokemons): i.refresh(inventory) - + self.update_web_inventory() - + def update_web_inventory(self): web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) - with open(web_inventory, "r") as infile: - json_inventory = json.load(infile) + if os.path.exists(web_inventory): + with open(web_inventory, "r") as infile: + json_inventory = json.load(infile) + + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] + json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] + + json_inventory = json_inventory + self.jsonify_inventory() + else: + json_inventory = self.jsonify_inventory() - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokedex_entry", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("candy", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("item", None)] - json_inventory = [x for x in json_inventory if not x.get("inventory_item_data", {}).get("pokemon_data", None)] - - json_inventory = json_inventory + self.jsonify_inventory() - with open(web_inventory, "w") as outfile: json.dump(json_inventory, outfile) def jsonify_inventory(self): json_inventory = [] - + for pokedex in self.pokedex.all(): json_inventory.append({"inventory_item_data": {"pokedex_entry": pokedex}})