-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
134 lines (107 loc) · 3.31 KB
/
Copy pathutils.py
File metadata and controls
134 lines (107 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""
utils.py
Small presentation/helper utilities for the CLI: printing headers,
menus, movie summaries, and movie detail screens. Keeping these
functions separate keeps main.py focused on control flow.
"""
from typing import List
from movie import Movie
DIVIDER = "=" * 32
def print_header(title: str, subtitle: str = "") -> None:
"""
Print a section header in the style used throughout the CLI.
Args:
title: The main title text (e.g. "MOVIEFINDER").
subtitle: An optional underline-style subtitle (e.g. "=========").
"""
print(DIVIDER)
print(title)
if subtitle:
print(subtitle)
else:
print("=" * len(title))
def print_main_menu() -> None:
"""Print the main CLI menu options."""
print_header("MOVIEFINDER")
print()
print("1. Search Movies")
print("2. View Favorites")
print("3. Search Favorites")
print("4. Remove Favorite")
print("5. Export Favorites")
print("6. Exit")
print()
def print_search_results(movies: List[Movie]) -> None:
"""
Print a numbered list of search result movies.
Args:
movies: The list of Movie objects to display.
"""
print()
print("Search Results:")
print()
for index, movie in enumerate(movies, start=1):
print(f"{index}. {movie.summary_line()}")
print()
def print_movie_details(movie: Movie) -> None:
"""
Print the full details screen for a single movie.
Args:
movie: The Movie object to display.
"""
print()
print_header("MOVIE DETAILS", "=============")
print()
print(f"Title: {movie.title}")
print(f"Year: {movie.year}")
print(f"Genre: {movie.genre}")
rating_display = movie.rating if movie.rating == "N/A" else f"{movie.rating}/10"
print(f"Rating: {rating_display}")
print(f"Runtime: {movie.runtime}")
print()
print("Plot:")
print(movie.plot)
print()
def print_favorites_list(movies: List[Movie]) -> None:
"""
Print a numbered list of favorite movies.
Args:
movies: The list of favorite Movie objects to display.
"""
print()
if not movies:
print("You have no favorite movies saved yet.")
print()
return
print("Your Favorite Movies:")
print()
for index, movie in enumerate(movies, start=1):
print(f"{index}. {movie.summary_line()} - {movie.genre}")
print()
def prompt_nonempty(prompt_text: str) -> str:
"""
Prompt the user for input, re-prompting until a non-empty value is given.
Args:
prompt_text: The text to display when prompting.
Returns:
str: The non-empty, stripped user input.
"""
while True:
value = input(prompt_text).strip()
if value:
return value
print("Input cannot be empty. Please try again.")
def prompt_choice(prompt_text: str, valid_choices: List[str]) -> str:
"""
Prompt the user until they enter one of the valid choices.
Args:
prompt_text: The text to display when prompting.
valid_choices: A list of acceptable string inputs.
Returns:
str: The valid choice entered by the user.
"""
while True:
value = input(prompt_text).strip()
if value in valid_choices:
return value
print(f"Invalid choice. Please enter one of: {', '.join(valid_choices)}")