From a4978871b4bfcf9e999572a4c79198324cef25f2 Mon Sep 17 00:00:00 2001 From: Michael Moore <5983927+MichaelMakesGames@users.noreply.github.com> Date: Tue, 7 Nov 2023 13:00:42 -0600 Subject: [PATCH] Fix errors extracting data from 3.9 gamestate (#113) * Fix errors extracting data from 3.9 gamestate * Fix eliasdoehne/stellaris-dashboard#111 --- README.md | 2 +- stellarisdashboard/parsing/rust_parser/src/parser.rs | 2 +- stellarisdashboard/parsing/timeline.py | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7d5204f..2eb1d8e 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ You can also access the dashboard by opening [http://localhost:28053](http://loc ### Build it yourself - Get Python 3.10 (it may work on other versions too) - (Recommended) create & activate a virtual environment -- `pip install .` +- `pip install .` (If you get a ModuleNotFoundError for importing stellarisdashboard, try instead `pip install -e .`) - `pip install maturin` and `maturin develop -r` in `stellarisdashboard/parsing/rust_parser` - `stellarisdashboard` diff --git a/stellarisdashboard/parsing/rust_parser/src/parser.rs b/stellarisdashboard/parsing/rust_parser/src/parser.rs index 010f42e..46ba107 100644 --- a/stellarisdashboard/parsing/rust_parser/src/parser.rs +++ b/stellarisdashboard/parsing/rust_parser/src/parser.rs @@ -245,7 +245,7 @@ fn parse_str(input: &str) -> IResult<&str, &str> { } fn _is_valid_unquoted_str_char(c: char) -> bool { - c.is_ascii_alphanumeric() || c == '_' || c == ':' || c == '.' + c.is_ascii_alphanumeric() || c == '_' || c == ':' || c == '.' || c == '@' } fn parse_unquoted_str(input: &str) -> IResult<&str, &str> { diff --git a/stellarisdashboard/parsing/timeline.py b/stellarisdashboard/parsing/timeline.py index 04076bb..52213d5 100644 --- a/stellarisdashboard/parsing/timeline.py +++ b/stellarisdashboard/parsing/timeline.py @@ -1448,7 +1448,9 @@ def extract_data_from_gamestate(self, dependencies): for country_id, country_model in self._countries_dict.items(): country_dict = self._gamestate_dict["country"][country_id] - country_sectors = country_dict.get("sectors", {}).get("owned", []) + # some countries have an empty object for "sectors", which gets parsed as an empty list + # so we need to wrap that in dict() + country_sectors = dict(country_dict.get("sectors", {})).get("owned", []) unprocessed_systems = set( s.system_id_in_game for s in self._systems_by_owner.get(country_id, []) ) @@ -2702,7 +2704,7 @@ def extract_data_from_gamestate(self, dependencies): envoy = leaders[envoy_id_ingame] country = envoy.country target_country = None - location = raw_leader_dict.get("location") + location = raw_leader_dict.get("location", {}) assignment = location.get("assignment") description = None if assignment == "improve_relations":