From 67314612114e9b7674be0efe28cc31cc232e33be Mon Sep 17 00:00:00 2001 From: Wrycu Date: Thu, 2 Jan 2020 21:36:40 -0800 Subject: [PATCH] fix(debrief): correct inability to parse debrief fixes #83 --- userdata/debriefing.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/userdata/debriefing.py b/userdata/debriefing.py index fe95f05..56b1567 100644 --- a/userdata/debriefing.py +++ b/userdata/debriefing.py @@ -88,6 +88,11 @@ def append_dead_object(object_mission_id_str): def parse_dead_object(event): try: append_dead_object(event["initiatorMissionID"]) + except KeyError: + try: + append_dead_object([x['initiatorMissionID'] for x in event.values() if 'initiatorMissionID' in x][0]) + except Exception as e: + logging.error(e) except Exception as e: logging.error(e) @@ -98,9 +103,20 @@ def parse_dead_object(event): except Exception as e: table = parse_mutliplayer_debriefing(table_string) - events = table.get("debriefing", {}).get("events", {}) + try: + events = table["debriefing"].get("events", {}) + except KeyError: + events = table.get('events', {}) for event in events.values(): - event_type = event.get("type", None) + try: + event_type = event["type"] + except KeyError: + # this means we've encountered a different version of the parsed debrief. This means we must search + # for the key we want :| + try: + event_type = [x['type'] for x in event.values() if 'type' in x][0] + except Exception as e: + print("Failed to parse event - {} ({})".format(event, e)) if event_type in ["crash", "dead"]: parse_dead_object(event) @@ -125,7 +141,7 @@ def count_groups(groups: typing.List[UnitType]) -> typing.Dict[UnitType, int]: player = mission.country(player_name) enemy = mission.country(enemy_name) - + player_units = count_groups(player.plane_group + player.vehicle_group + player.ship_group) enemy_units = count_groups(enemy.plane_group + enemy.vehicle_group + enemy.ship_group)