Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -25,12 +25,15 @@ def get_random_excuse() -> str:
|
|
25 |
"""
|
26 |
try:
|
27 |
response = requests.get('https://excuser.herokuapp.com/')
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
32 |
else:
|
33 |
-
return "
|
34 |
except Exception as e:
|
35 |
return f"Error fetching random excuse: {str(e)}"
|
36 |
|
|
|
25 |
"""
|
26 |
try:
|
27 |
response = requests.get('https://excuser.herokuapp.com/')
|
28 |
+
if response.status_code == 200:
|
29 |
+
data = response.json()
|
30 |
+
if data and len(data) > 0 and 'excuse' in data[0]:
|
31 |
+
excuse = data[0]['excuse']
|
32 |
+
return f"Here's a random excuse: {excuse}"
|
33 |
+
else:
|
34 |
+
return "No excuse found. Please try again."
|
35 |
else:
|
36 |
+
return f"API returned an error: {response.status_code}"
|
37 |
except Exception as e:
|
38 |
return f"Error fetching random excuse: {str(e)}"
|
39 |
|