From 725b480cb455ed983eca4907a842643114da03da Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 25 May 2026 19:07:31 +0200 Subject: [PATCH] Default output to logs/YYYY_MM_DD_HH_MM_SS_.log When -o is omitted, the output file is auto-named from the run's start timestamp and the vehicle VIN and placed under ./logs/, which is created on demand. logs/ is gitignored. Co-Authored-By: Claude Sonnet 4.6 --- .gitignore | 3 ++- collect.py | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index bb1e8ed..aa78891 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ credentials/ -vehicle_data.json \ No newline at end of file +vehicle_data.json +logs/ \ No newline at end of file diff --git a/collect.py b/collect.py index b8483f1..98b5b01 100644 --- a/collect.py +++ b/collect.py @@ -12,7 +12,10 @@ Usage examples export WC_USER=me@example.com WC_PASS=secret python collect.py -# Credentials from a JSON file: +# Credentials from a JSON file (output auto-named under ./logs/): + python collect.py -c creds.json -i 600 + +# Credentials from a JSON file, explicit output path: python collect.py -c creds.json -i 600 -o id3.json # Custom domains, 10-minute interval: @@ -378,8 +381,6 @@ def run(args: argparse.Namespace) -> None: log.error("Unknown domain(s): %s. Available: %s", unknown, list(ALL_DOMAINS)) sys.exit(1) - out = Path(args.output) - log.info("Connecting to WeConnect…") wc = weconnect.WeConnect( username=args.username, @@ -410,6 +411,14 @@ def run(args: argparse.Namespace) -> None: vin = vehicle.vin.value log.info("Vehicle: %s", vin) + if args.output: + out = Path(args.output) + else: + logs_dir = Path("logs") + logs_dir.mkdir(exist_ok=True) + stamp = datetime.now().strftime("%Y_%m_%d_%H_%M_%S") + out = logs_dir / f"{stamp}_{vin}.log" + store = load_store(out, vin, args.interval) log.info( "Collecting [%s] every %ds → %s (Ctrl-C to stop)", @@ -487,9 +496,9 @@ def main() -> None: ) p.add_argument( "-o", "--output", - default="vehicle_data.json", + default=None, metavar="FILE", - help="Output JSON file (default: vehicle_data.json)", + help="Output file (default: logs/YYYY_MM_DD_HH_MM_SS_.log)", ) p.add_argument( "--max-records",