Gianpaolo Macario
commited on
Commit
·
3af69cf
1
Parent(s):
d0ce3d8
docs(app): add docstring to get_dad_joke()
Browse files
app.py
CHANGED
@@ -17,6 +17,19 @@ def greet(name: str) -> str:
|
|
17 |
return "Hello " + name + "!!"
|
18 |
|
19 |
def get_dad_joke():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
headers = {"Accept": "application/json"}
|
21 |
response = requests.get("https://icanhazdadjoke.com/", headers=headers)
|
22 |
if response.status_code == 200:
|
|
|
17 |
return "Hello " + name + "!!"
|
18 |
|
19 |
def get_dad_joke():
|
20 |
+
"""
|
21 |
+
Fetches a random dad joke from the icanhazdadjoke.com API.
|
22 |
+
The function makes an HTTP GET request to the icanhazdadjoke API
|
23 |
+
with appropriate headers to receive JSON response.
|
24 |
+
Returns:
|
25 |
+
str: A random dad joke if successful, otherwise returns an error message.
|
26 |
+
- Success: Returns the joke text
|
27 |
+
- Failure: Returns "Failed to retrieve a joke." if the API request fails
|
28 |
+
- No joke: Returns "No joke found." if the API response doesn't contain a joke
|
29 |
+
Requires:
|
30 |
+
requests: The requests library must be imported to make HTTP requests
|
31 |
+
"""
|
32 |
+
|
33 |
headers = {"Accept": "application/json"}
|
34 |
response = requests.get("https://icanhazdadjoke.com/", headers=headers)
|
35 |
if response.status_code == 200:
|