Skip to content

Commit

Permalink
refactor: improve ask_file_path function
Browse files Browse the repository at this point in the history
This commit refactors the ask_file_path function in the main.py file. The function now includes separate logic for when the file location is "Provide path" and when it is not. It also introduces a validation function to check if the provided path is a valid file or an empty string. This refactoring improves code readability and maintainability by separating concerns and promoting code reuse.
  • Loading branch information
Lucs1590 committed May 26, 2024
1 parent a3c83d6 commit 9c29a62
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,18 @@ def download_tcx_file(activity_id: str, sport: str) -> None:
raise ValueError("Error opening the browser") from err


def ask_file_path(file_location) -> str:
question = "Enter the path to the TCX file:" if file_location == "Provide path" else "Check if the TCX was downloaded and validate the file:"
def ask_file_path(file_location: str) -> str:
if file_location == "Provide path":
question = "Enter the path to the TCX file:"
def validation(path): return os.path.isfile(path)
else:
question = "Check if the TCX was downloaded and validate the file:"
def validation(path): return os.path.isfile(path) or path == ''

return questionary.path(
question,
validate=lambda path: path == '' or os.path.isfile(path),
validate=validation,
only_directories=False
).ask()


Expand Down

0 comments on commit 9c29a62

Please sign in to comment.