From 0fe5e17b65fdd6152cb95d6a85d03532170823f2 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Dec 2022 16:25:25 +0000 Subject: [PATCH] CAPI: Fix `dump_capi_data()` for `/fleetcarrier` Still produces the system/station: `HIP 10792.Crimson Exchange.2022-12-30T16.22.39.json` But now also the FC: `FleetCarrier.X3F-N5Z.2022-12-30T16.24.01.json` --- companion.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/companion.py b/companion.py index b7ccd093..88bdd7e1 100644 --- a/companion.py +++ b/companion.py @@ -1125,24 +1125,27 @@ class Session(object): def dump_capi_data(self, data: CAPIData) -> None: """Dump CAPI data to file for examination.""" if os.path.isdir('dump'): - try: - system = data['lastSystem']['name'] + file_name: str = "" + if data.source_endpoint == self.FRONTIER_CAPI_PATH_FLEETCARRIER: + file_name += f"FleetCarrier.{data['name']['callsign']}" - except (KeyError, ValueError): - system = '' + else: + try: + file_name += data['lastSystem']['name'] - try: - if data['commander'].get('docked'): - station = f'.{data["lastStarport"]["name"]}' + except (KeyError, ValueError): + file_name += 'unknown system' - else: - station = '' + try: + if data['commander'].get('docked'): + file_name += f'.{data["lastStarport"]["name"]}' - except (KeyError, ValueError): - station = '' + except (KeyError, ValueError): + file_name += '.unknown station' - timestamp = time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime()) - with open(f'dump/{system}{station}.{timestamp}.json', 'wb') as h: + file_name += time.strftime('.%Y-%m-%dT%H.%M.%S', time.localtime()) + file_name += '.json' + with open(f'dump/{file_name}', 'wb') as h: h.write(json.dumps(data, cls=CAPIDataEncoder, ensure_ascii=False, indent=2,