From 62a7ac574fddc429869bf2fceb009ca6f8efce84 Mon Sep 17 00:00:00 2001 From: Marc Koch Date: Mon, 16 Sep 2024 14:48:42 +0200 Subject: [PATCH] fix support for csv file argument --- src/cgnappointments/__main__.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/cgnappointments/__main__.py b/src/cgnappointments/__main__.py index 7ebb26e..479e48a 100644 --- a/src/cgnappointments/__main__.py +++ b/src/cgnappointments/__main__.py @@ -57,6 +57,13 @@ def parse_arguments() -> dict: help="Path to the configuration file", required=False, ) + argparser.add_argument( + "--csv-file", + action="store", + type=Path, + help="Path to the csv file, which stores the last fetched dates", + required=False, + ) argparser.add_argument( "--log-file", action="store", @@ -85,7 +92,7 @@ def update_config_with_args(config: dict, args: dict) -> dict: update_config = { "services": args.get("services"), "locations": args.get("locations"), - "csv_path": args.get("csv_path"), + "csv_path": args.get("csv_file"), } for key, value in update_config.items(): if value is not None: @@ -139,16 +146,21 @@ def define_csv_path(csv_path: str|None, csv_name: str|None) -> Path: csv_path = Path(csv_path) if csv_path else None csv_name = Path(csv_name) if csv_name else None - if csv_path is not None and csv_path.is_file(): - return csv_path - elif csv_path is not None and csv_path.is_dir() and csv_name is not None: + if csv_path is not None and csv_path.is_dir() and csv_name is not None: return csv_path / csv_name elif csv_path is not None and csv_path.is_dir() and csv_name is None: return csv_path / "cgn-appointments.csv" + elif csv_path is not None: + csv_path.touch() + return csv_path elif csv_name is not None: - return Path(user_data_dir()) / csv_name + csv_path = Path(user_data_dir()) / csv_name + csv_path.touch() + return csv_path else: - return Path(user_data_dir()) / "cgn-appointments.csv" + csv_path = Path(user_data_dir()) / "cgn-appointments" + csv_path.touch() + return csv_path / "cgn-appointments.csv" def select_options(services, selects):