From c61f2357347e6edddf6661b2d316afa99183a57d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 5 Dec 2022 10:55:53 +0000 Subject: [PATCH] loadout.py: Collapse the construction of output filename All the intermediate variables were more a "work in progress" thing. Tested as still working. --- loadout.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/loadout.py b/loadout.py index 805f245a..2e2061a2 100644 --- a/loadout.py +++ b/loadout.py @@ -49,19 +49,11 @@ def export(data: companion.CAPIData, requested_filename: Optional[str] = None) - query_time = config.get_int('querytime', default=int(time.time())) # Write - # - # When this is refactored into multi-line CHECK IT WORKS, avoiding the - # brainfart we had with dangling commas in commodity.py:export() !!! - # - output_path = pathlib.Path(config.get_str('outdir')) - output_filename = pathlib.Path( - ship + '.' + time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(query_time)) + '.txt' - ) - # Can't re-use `filename`, different type - file_name = output_path / output_filename - # - # When this is refactored into multi-line CHECK IT WORKS, avoiding the - # brainfart we had with dangling commas in commodity.py:export() !!! - # - with open(file_name, 'wt') as h: + + with open( + pathlib.Path(config.get_str('outdir')) / pathlib.Path( + ship + '.' + time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(query_time)) + '.txt' + ), + 'wt' + ) as h: h.write(string)