diff --git a/pokemongo_bot/cell_workers/update_live_stats.py b/pokemongo_bot/cell_workers/update_live_stats.py index f7ae1877e6..5b412cba4d 100644 --- a/pokemongo_bot/cell_workers/update_live_stats.py +++ b/pokemongo_bot/cell_workers/update_live_stats.py @@ -1,10 +1,13 @@ import ctypes +import json +import os from sys import stdout, platform as _platform from datetime import datetime, timedelta from pokemongo_bot.base_task import BaseTask from pokemongo_bot.worker_result import WorkerResult from pokemongo_bot.tree_config_builder import ConfigException +from pokemongo_bot.base_dir import _base_dir class UpdateLiveStats(BaseTask): @@ -92,11 +95,15 @@ def work(self): """ if not self._should_display(): return WorkerResult.SUCCESS - line = self._get_stats_line(self._get_player_stats()) + + player_stats = self._get_player_stats() + line = self._get_stats_line(player_stats) # If line is empty, it couldn't be generated. if not line: return WorkerResult.SUCCESS - + + self.update_web_stats(player_stats) + if self.terminal_title: self._update_title(line, _platform) @@ -356,3 +363,17 @@ def _get_player_stats(self): for x in inventory_items if x.get("inventory_item_data", {}).get("player_stats", {})), None) + + def update_web_stats(self,player_data): + web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) + + with open(web_inventory, "r") as infile: + json_stats = json.load(infile) + + json_stats = [x for x in json_stats if not x.get("inventory_item_data", {}).get("player_stats", None)] + + for player_stat in player_data: + json_stats.append({"inventory_item_data": {"player_stats": player_data}}) + + with open(web_inventory, "w") as outfile: + json.dump(json_stats, outfile) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index e20fa3ad5d..7a7c341fb1 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -1098,20 +1098,15 @@ def refresh(self): def update_web_inventory(self): web_inventory = os.path.join(_base_dir, "web", "inventory-%s.json" % self.bot.config.username) - json_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)] - inventory_items = self.bot.api.get_inventory() \ - .get('responses', {}) \ - .get('GET_INVENTORY', {}) \ - .get('inventory_delta', {}) \ - .get('inventory_items', {}) - player_data = next((x["inventory_item_data"]["player_stats"] - for x in inventory_items - if x.get("inventory_item_data", {}).get("player_stats", {})), - None) - for player_stat in player_data: - json_inventory.append({"inventory_item_data": {"player_stats": player_data}}) - for pokedex in self.pokedex.all(): json_inventory.append({"inventory_item_data": {"pokedex_entry": pokedex}})