Spaces:
Sleeping
Sleeping
yash-b18 commited on
Commit ·
f78d74e
1
Parent(s): 8af6c7f
Update to CLI to prevent crashing on invalid inputs
Browse files- met_api.py +9 -3
met_api.py
CHANGED
|
@@ -185,16 +185,22 @@ def search_for_images(query,
|
|
| 185 |
Then searches the department based on input, and displays the results with images.
|
| 186 |
"""
|
| 187 |
def main():
|
| 188 |
-
print("Welcome to Met Search")
|
| 189 |
departments = list_met_departments()
|
| 190 |
print(departments.to_string(index=False))
|
| 191 |
random.seed(time.time())
|
| 192 |
while True:
|
| 193 |
-
dept_no = input("Choose a departmentId #: (or enter for all)").strip()
|
| 194 |
-
if dept_no
|
|
|
|
|
|
|
| 195 |
dept = None
|
| 196 |
else:
|
|
|
|
|
|
|
|
|
|
| 197 |
dept = [int(dept_no)]
|
|
|
|
| 198 |
query = input("Search the Met for: ").strip()
|
| 199 |
if query == '':
|
| 200 |
print("Please enter a query.")
|
|
|
|
| 185 |
Then searches the department based on input, and displays the results with images.
|
| 186 |
"""
|
| 187 |
def main():
|
| 188 |
+
print("Welcome to Met Search.")
|
| 189 |
departments = list_met_departments()
|
| 190 |
print(departments.to_string(index=False))
|
| 191 |
random.seed(time.time())
|
| 192 |
while True:
|
| 193 |
+
dept_no = input("Choose a departmentId #: (Type 'q', 'quit' to stop the program, or enter for all) ").strip()
|
| 194 |
+
if dept_no.lower() in ['q', 'quit']:
|
| 195 |
+
break
|
| 196 |
+
elif dept_no == '':
|
| 197 |
dept = None
|
| 198 |
else:
|
| 199 |
+
if not dept_no.isdigit():
|
| 200 |
+
print("Invalid input. Please try again.")
|
| 201 |
+
continue
|
| 202 |
dept = [int(dept_no)]
|
| 203 |
+
|
| 204 |
query = input("Search the Met for: ").strip()
|
| 205 |
if query == '':
|
| 206 |
print("Please enter a query.")
|