From af50a9f59d074a9a584560c680c24f93c9f426f6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 31 Aug 2021 12:44:46 +0100 Subject: [PATCH] companion: Make raw_data.__str__() a little less verbose NB: We can't use a generator here to make a python object of the data, to then use json.dumps() on because the raw_data is a *string* (decoded from what we received from the CAPI service), and thus it will get encoded as such, i.e. "raw_data": "{\"id\":322... when we want: "raw_data": {"id":322... We do not want to json.loads() that string only to then json.dumps() it because the whole point is that this is the **raw** data to help diagnose any issues with the CAPI service/data. Such a conversion and back could either throw an exception we don't want here (because we want the raw data) or possibly distort things from what was actually received. --- companion.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/companion.py b/companion.py index 3fc4c817..1d7f1b89 100644 --- a/companion.py +++ b/companion.py @@ -158,9 +158,9 @@ class CAPIDataRaw: def __str__(self): """Return a more readable string form of the data.""" capi_data_str = '{' - for e in self.raw_data.keys(): - capi_data_str += f'"{e}":\n{{\n\t"query_time": "{self.raw_data[e].query_time}",\n\t' \ - f'"raw_data": {self.raw_data[e].raw_data}\n}},\n\n' + for k, v in self.raw_data.items(): + capi_data_str += f'"{k}":\n{{\n\t"query_time": "{v.query_time}",\n\t' \ + f'"raw_data": {v.raw_data}\n}},\n\n' capi_data_str = capi_data_str.removesuffix(',\n\n') capi_data_str += '\n\n}'