~xenrox/status-display

status-display/status-display.py -rw-r--r-- 1.9 KiB
893f85f3Thorben Günther Rename config.ini to example.ini 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import configparser

import driver as epd
from modules.mail import get_unread
from modules.server import is_up
from modules.timestamp import timestamp_str
from modules.weather import get_weather
from PIL import Image, ImageDraw, ImageFont

font45 = ImageFont.truetype("Roboto-Bold.ttf", 45)
font90 = ImageFont.truetype("Roboto-Bold.ttf", 90)
w_font45 = ImageFont.truetype("./weathericons-regular-webfont.ttf", 45)
w_font80 = ImageFont.truetype("./weathericons-regular-webfont.ttf", 80)

config = configparser.ConfigParser()
config.read("config.ini")

epd = epd.EPD()
epd.init()

Himage = Image.new("1", (epd.width, epd.height), 255)
draw = ImageDraw.Draw(Himage)

# Border
draw.line((430, 0, 430, 330), fill=0, width=5)
draw.line((0, 330, 430, 330), fill=0, width=5)

# Weather
current, daily = get_weather(
    config.get("weather", "apikey"),
    config.get("weather", "latitude"),
    config.get("weather", "longitude"),
)
draw.text((30, 0), current[0], font=w_font80, fill=0)
draw.text((180, 0), "{}°C".format(current[1]), font=font90, fill=0)

y = 130
for i in range(len(daily)):
    draw.text((30, y), daily[i][0], font=font45, fill=0)
    draw.text((130, y - 5), daily[i][3], font=w_font45, fill=0)
    draw.text((220, y), "{} | {}".format(daily[i][1], daily[i][2]), font=font45, fill=0)
    y += 70

# Server status
server = config._sections["server"]
for name in server:
    draw.text((30, y), "{}: {}".format(name, is_up(server[name])), font=font45, fill=0)
    y += 70

y = 0
# Time
draw.text((440, y), timestamp_str(), font=font45, fill=0)
y = +70

# Unread mails
draw.text(
    (440, y),
    "Mail: {}".format(
        get_unread(
            config.get("mail", "ip"),
            config.get("mail", "port"),
            config.get("mail", "user"),
            config.get("mail", "password"),
        )
    ),
    font=font45,
    fill=0,
)

buffer = epd.getbuffer(Himage)
epd.clear()
epd.display(buffer)
epd.sleep()