Updated lock file

This commit is contained in:
Bart Koolen 2026-02-08 20:32:32 +01:00
parent 275e8b605e
commit 4199ff721d
3 changed files with 39 additions and 3 deletions

6
flake.lock generated
View file

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1760524057,
"narHash": "sha256-EVAqOteLBFmd7pKkb0+FIUyzTF61VKi7YmvP1tw4nEw=",
"lastModified": 1770197578,
"narHash": "sha256-AYqlWrX09+HvGs8zM6ebZ1pwUqjkfpnv8mewYwAo+iM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "544961dfcce86422ba200ed9a0b00dd4b1486ec5",
"rev": "00c21e4c93d963c50d4c0c89bfa84ed6e0694df2",
"type": "github"
},
"original": {

View file

@ -35,6 +35,7 @@
virtualenv
requests
pandas
types-requests
# Optional: Add other helpful dev tools outside of the python-pkgs set if needed
# (e.g., git, pre-commit, bash-completion)
]))

35
src/dad_joke.py Normal file
View 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()