Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import glob
import os
from sys import exit
import time
from datetime import datetime
from font_fredoka_one import FredokaOne
from inky.auto import auto
from PIL import Image, ImageDraw, ImageFont
from weather_report import fetch_weather
# Get the current path
PATH = os.path.dirname(__file__)
# Set up the display
try:
inky_display = auto(ask_user=True, verbose=True)
except TypeError:
raise TypeError("You need to update the Inky library to >= v1.1.0")
inky_display.set_border(inky_display.BLACK)
# Create a new canvas to draw on
# Size 212x104
img = Image.open(os.path.join(PATH, "recursive.png")).resize(inky_display.resolution)
draw = ImageDraw.Draw(img)
WIDTH=212
HEIGHT=104
# Load the FredokaOne font
font = ImageFont.truetype(FredokaOne, 16)
def clear_draw():
draw.rectangle((0, 0, WIDTH, HEIGHT), inky_display.BLACK)
while True:
current_time = datetime.now().strftime("%d/%m %H:%M:%S")
report = fetch_weather()
if hasattr(report, "error_code"):
text = "Time: {}\nError: {}\n{}".format(current_time, report.error_code, report.message)
print(text)
print(report.response)
clear_draw()
draw.text((4, 12), text, inky_display.WHITE, font=font)
# Display the error on Inky pHAT
inky_display.set_image(img)
inky_display.show()
thirty_minutes = 60*30
time.sleep(thirty_minutes)
continue
weather_log = "Time: {}\nTemp: {}F\nFeels Like: {}F\nHigh: {}F/Low: {}F\nHumidity: {}".format(
current_time,
report.current_temperature,
report.feels_like,
report.high,
report.low,
report.humidity
)
print(weather_log)
text = "{}".format(weather_log)
clear_draw()
draw.text((4, 4), text, inky_display.WHITE, font=font)
# Display the weather data on Inky pHAT
inky_display.set_image(img)
inky_display.show()
ten_minutes = 60*10
time.sleep(ten_minutes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment