diff --git a/bimmer_connected/account.py b/bimmer_connected/account.py index b7915857..5377771b 100644 --- a/bimmer_connected/account.py +++ b/bimmer_connected/account.py @@ -10,8 +10,8 @@ import datetime import logging +import pathlib import urllib -import os import json from threading import Lock from typing import Callable, List @@ -42,7 +42,7 @@ class ConnectedDriveAccount: # pylint: disable=too-many-instance-attributes """ # pylint: disable=too-many-arguments - def __init__(self, username: str, password: str, region: Regions, log_responses: str = None, + def __init__(self, username: str, password: str, region: Regions, log_responses: pathlib.Path = None, retries_on_500_error: int = 5) -> None: self._region = region self._server_url = None @@ -183,8 +183,8 @@ def _log_response_to_file(self, response: requests.Response, logfilename: str = output_path = None count = 0 - while output_path is None or os.path.exists(output_path): - output_path = os.path.join(self._log_responses, '{}_{}.txt'.format(logfilename, count)) + while output_path is None or output_path.exists(): + output_path = self._log_responses / '{}_{}.txt'.format(logfilename, count) count += 1 with open(output_path, 'w') as logfile: diff --git a/bimmer_connected/cli.py b/bimmer_connected/cli.py index e361b921..47cf3c40 100644 --- a/bimmer_connected/cli.py +++ b/bimmer_connected/cli.py @@ -4,19 +4,17 @@ import argparse import logging import json -import os import time import sys +from pathlib import Path + import requests from bimmer_connected.account import ConnectedDriveAccount from bimmer_connected.country_selector import get_region_from_name, valid_regions from bimmer_connected.vehicle import VehicleViewDirection -FINGERPRINT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), - 'vehicle_fingerprint') - TEXT_VIN = 'Vehicle Identification Number' @@ -106,9 +104,8 @@ def get_status(args) -> None: def fingerprint(args) -> None: """Save the vehicle fingerprint.""" - time_str = time.strftime("%Y-%m-%d_%H-%M-%S") - time_dir = os.path.join(FINGERPRINT_DIR, time_str) - os.makedirs(time_dir) + time_dir = Path.home() / 'vehicle_fingerprint' / time.strftime("%Y-%m-%d_%H-%M-%S") + time_dir.mkdir(parents=True) account = ConnectedDriveAccount(args.username, args.password, get_region_from_name(args.region), log_responses=time_dir)