Skip to content

Instantly share code, notes, and snippets.

@itsthejoker
Created March 13, 2021 21:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsthejoker/33c390748fd8d4184ca81d421b69f9e6 to your computer and use it in GitHub Desktop.
Save itsthejoker/33c390748fd8d4184ca81d421b69f9e6 to your computer and use it in GitHub Desktop.
Random dadjoke from fatherhood.gov
#!/usr/bin/env python
# source: 'https://gist.github.com/itsthejoker/33c390748fd8d4184ca81d421b69f9e6'
from urllib import request
import json
import random
resp = request.urlopen("https://fatherhood.gov/jsonapi/node/dad_jokes")
joke = random.choice(json.loads(resp.read()).get('data')).get('attributes')
if joke:
print(joke.get('field_joke_opener'))
print(joke.get('field_joke_response'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment