Skip to content

Instantly share code, notes, and snippets.

@jlafourc
Created March 25, 2026 06:40
Show Gist options
  • Select an option

  • Save jlafourc/d793645a9b3cb2203f3781e39d70180e to your computer and use it in GitHub Desktop.

Select an option

Save jlafourc/d793645a9b3cb2203f3781e39d70180e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import glob
import json
import os
import time
from nob import Nob
import requests
from sys import exit
import datetime
from font_hanken_grotesk import HankenGroteskBold, HankenGroteskMedium
from font_fredoka_one import FredokaOne
from PIL import Image, ImageDraw, ImageFont
from inky.auto import auto
# Get the current path
PATH = os.path.dirname(__file__)
# Set up the display
try:
inky_display = auto()
except TypeError:
raise TypeError("You need to update the Inky library to >= v1.1.0")
if inky_display.resolution not in ((212, 104), (250, 122)):
w, h = inky_display.resolution
raise RuntimeError("This example does not support {}x{}".format(w, h))
inky_display.set_border(inky_display.BLACK)
inky_display.h_flip = False
inky_display.v_flip = False
def getsize(font, text):
_, _, right, bottom = font.getbbox(text)
return (right, bottom)
scale_size = 1.30
hanken_bold_font = ImageFont.truetype(HankenGroteskBold, int(16 * scale_size))
# Dictionaries to store our icons and icon masks in
icons = {}
masks = {}
now = datetime.datetime.now()
today630 = now.replace(hour=6, minute=30, second=0, microsecond=0)
today830 = now.replace(hour=9, minute=30, second=0, microsecond=0)
if now > today630 and now < today830:
if os.path.exists("/home/jlafourc/.idelis-lock"):
os.remove("/home/jlafourc/.idelis-lock")
r = requests.request(method='get', url='https://api.idelis.fr/GetStopMonitoring', data=json.dumps({
"code" : "LAGUTS_1",
"ligne" : "5",
"next" : 3
#"code" : "F-HDES_2",
#"ligne" : "F",
#"next" : 3
}), headers={'X-Auth-Token': '<token>'})
nob_tree = Nob(r.json())
arrivee = nob_tree.passages[0].arrivee[:] or "A l'arrêt" if nob_tree.find("passages") else "Aucun passage"
# Create a new canvas to draw on
img = Image.new("P", inky_display.resolution)
draw = ImageDraw.Draw(img)
hello_w, hello_h = getsize(hanken_bold_font, arrivee)
hello_x = int((inky_display.width - 92 - hello_w) / 2) + 92
hello_y = int((inky_display.height - hello_h) / 2)
draw.text((hello_x, hello_y), arrivee, inky_display.BLACK, font=hanken_bold_font)
# Load our icon files and generate masks
icon_image = Image.open("resources/bus-icon.png")
icons["bus"] = icon_image
img.paste(icons["bus"], (28, 30))
# Display the weather data on Inky pHAT
inky_display.set_image(img)
inky_display.show()
elif not os.path.isfile("/home/jlafourc/.idelis-lock"):
open("/home/jlafourc/.idelis-lock", "a")
img= Image.new("P", inky_display.resolution)
draw = ImageDraw.Draw(img)
hello_w, hello_h = getsize(hanken_bold_font, "En veille")
hello_x = int((inky_display.width - hello_w) /2)
hello_y = int((inky_display.height - hello_h) / 2)
draw.text((hello_x, hello_y), "En veille", inky_display.BLACK, font=hanken_bold_font)
inky_display.set_image(img)
inky_display.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment