Updated lock file
This commit is contained in:
parent
275e8b605e
commit
4199ff721d
3 changed files with 39 additions and 3 deletions
6
flake.lock
generated
6
flake.lock
generated
|
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760524057,
|
"lastModified": 1770197578,
|
||||||
"narHash": "sha256-EVAqOteLBFmd7pKkb0+FIUyzTF61VKi7YmvP1tw4nEw=",
|
"narHash": "sha256-AYqlWrX09+HvGs8zM6ebZ1pwUqjkfpnv8mewYwAo+iM=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "544961dfcce86422ba200ed9a0b00dd4b1486ec5",
|
"rev": "00c21e4c93d963c50d4c0c89bfa84ed6e0694df2",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
virtualenv
|
virtualenv
|
||||||
requests
|
requests
|
||||||
pandas
|
pandas
|
||||||
|
types-requests
|
||||||
# Optional: Add other helpful dev tools outside of the python-pkgs set if needed
|
# Optional: Add other helpful dev tools outside of the python-pkgs set if needed
|
||||||
# (e.g., git, pre-commit, bash-completion)
|
# (e.g., git, pre-commit, bash-completion)
|
||||||
]))
|
]))
|
||||||
|
|
|
||||||
35
src/dad_joke.py
Normal file
35
src/dad_joke.py
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
import requests
|
||||||
|
|
||||||
|
def get_joke():
|
||||||
|
try:
|
||||||
|
api_url = "https://icanhazdadjoke.com/"
|
||||||
|
|
||||||
|
# VERY IMPORTANT: request JSON response
|
||||||
|
headers = {
|
||||||
|
"Accept": "application/json",
|
||||||
|
"User-Agent": "python-script (learning requests)"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Send GET request
|
||||||
|
response = requests.get(api_url, headers=headers)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
joke_data = response.json()
|
||||||
|
|
||||||
|
print("Joke:")
|
||||||
|
print(joke_data.get("joke", "No joke found."))
|
||||||
|
|
||||||
|
else:
|
||||||
|
print(f"Error: {response.status_code}")
|
||||||
|
print(response.text) # useful debugging
|
||||||
|
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"Network error: {e}")
|
||||||
|
except ValueError as e:
|
||||||
|
# This is the JSON decode error you were hitting
|
||||||
|
print("Server did not return valid JSON!")
|
||||||
|
print("Raw response was:")
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
|
get_joke()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue