-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_splash_image.py
executable file
·47 lines (40 loc) · 1.48 KB
/
create_splash_image.py
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
#!/usr/bin/env python3
import netifaces as ni
import requests
import time
from decouple import config
from helper import count_files
from PIL import Image, ImageDraw, ImageFont
DEBUG = config('DEBUG', default=False, cast=bool)
image_text = f"E-Mail: {config('EMAIL_USER')}\n"
image_counter = count_files(config('PROJECT_PATH') + '/pictures')
if image_counter > 0:
# change info text of the splash image here
image_text += f"Bilder: {image_counter}\n\n"
else:
image_text += "\n"
connected = False
for i in range(11):
try:
req = requests.get("https://google.com", timeout=5)
connected = True
break
except (requests.ConnectionError, requests.Timeout):
time.sleep(5)
pass
if connected:
ip_address = ni.ifaddresses(config('NETWORK_DEVICE'))[ni.AF_INET][0]['addr']
# change info text of the splash image here
# the network path should match with the Samba configuration
image_text += f'Freigabe: \\\\{ip_address}\\bilder'
else:
image_text += config('NETWORK_ERROR')
# switched because of portrait mode
width = config('SCREEN_HEIGHT', cast=int)
height = config('SCREEN_WIDTH', cast=int)
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
size=config('FONT_SIZE', cast=int))
img = Image.new('RGB', (width, height), color='black')
imgDraw = ImageDraw.Draw(img)
imgDraw.text((10, 10), image_text, font=font, fill=(119, 136, 153))
img.save(config('PROJECT_PATH') + '/site_data/splash.png')