Skip to content

Instantly share code, notes, and snippets.

@extrasleepy
Created March 9, 2022 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save extrasleepy/04873151f3735aa3ae128563a5bcaa83 to your computer and use it in GitHub Desktop.
Save extrasleepy/04873151f3735aa3ae128563a5bcaa83 to your computer and use it in GitHub Desktop.
import time
from requests import get
import json
import requests
import textwrap
from inky import InkyWHAT
from PIL import Image, ImageFont, ImageDraw
inky_display = InkyWHAT("black")
inky_display.set_border(inky_display.BLACK)
img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)
from font_fredoka_one import FredokaOne
font = ImageFont.truetype(FredokaOne, 36)
url = "https://dad-jokes.p.rapidapi.com/random/joke"
headers = {
'x-rapidapi-host': "dad-jokes.p.rapidapi.com",
'x-rapidapi-key': "your-API-Key"
}
#print(total)
while True:
response = requests.request("GET", url, headers=headers)
total=response.json()
setup = total['body'][0]['setup']
#setup = "how many ducks does it take to drive a car?"
print(setup)
punchline = total['body'][0]['punchline']
#punchline = "more ducks than you can imagine. It will blow your mind"
print(punchline)
message = setup
wrappedText = textwrap.wrap(message, width=22)
# The length-wrapped text is a list, so join it to one string using linebreaks
# (Each element in the list is a new line of text)
joinedText = "\n".join(wrappedText)
w, h = font.getsize(joinedText)
x = 10
y = 10
draw.text((x, y), joinedText, inky_display.BLACK, font)
inky_display.set_image(img)
inky_display.show()
time.sleep(5)
img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)
message = punchline
wrappedText = textwrap.wrap(message, width=22)
# The length-wrapped text is a list, so join it to one string using linebreaks
# (Each element in the list is a new line of text)
joinedText = "\n".join(wrappedText)
w, h = font.getsize(joinedText)
x = 10
y = 10
draw.text((x, y), joinedText, inky_display.BLACK, font)
inky_display.set_image(img)
inky_display.show()
time.sleep(20)
img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment