first draft
parent
15df2eff31
commit
185e586766
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"photo_folder": "/home/pi/fotobox_bilder",
|
||||||
|
"qr_path": "/home/pi/fotobox/qr_small.png",
|
||||||
|
"photo_prefix": "bh_sommerparty_23",
|
||||||
|
"qr_image": null,
|
||||||
|
"width": 1920,
|
||||||
|
"height": 1080
|
||||||
|
}
|
|
@ -0,0 +1,119 @@
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
import configparser
|
||||||
|
import logging
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
import _thread
|
||||||
|
|
||||||
|
import uploader
|
||||||
|
|
||||||
|
|
||||||
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
PIN_BUTTON = 22
|
||||||
|
|
||||||
|
def get_config():
|
||||||
|
"""Read config from ./config.ini"""
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read('config.json')
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def get_file_name(prefix="photobox", path="~"):
|
||||||
|
# name mit Timestamp versehen
|
||||||
|
ts = time.gmtime()
|
||||||
|
readable_ts = time.strftime("%H_%M_%S", ts)
|
||||||
|
photo_name = "/" + prefix + readable_ts + ".jpg"
|
||||||
|
return path + photo_name
|
||||||
|
|
||||||
|
|
||||||
|
def display_qr(screen, qr):
|
||||||
|
screen.blit(qr, (1330, 700))
|
||||||
|
pygame.display.flip()
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
|
||||||
|
def load_image(img_path):
|
||||||
|
return pygame.image.load(img_path).convert()
|
||||||
|
|
||||||
|
def display_image(screen, img, width, height):
|
||||||
|
try:
|
||||||
|
img = pygame.transform.scale(img, (width, height))
|
||||||
|
screen.blit(img, (0, 0))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
pygame.display.flip()
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
|
||||||
|
def display_text(screen, text, color=(20, 240, 100), size=70):
|
||||||
|
font = pygame.freetype.Font(
|
||||||
|
"/usr/share/fonts/truetype/liberation2/LiberationSans-Bold.ttf", size
|
||||||
|
)
|
||||||
|
text_renderd, text_rect = font.render(text, color)
|
||||||
|
screen_rect = screen.get_rect()
|
||||||
|
text_rect.centerx = screen_rect.centerx
|
||||||
|
screen.blit(text_renderd, (50, 50))
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
def io_remote():
|
||||||
|
# wait for button press
|
||||||
|
GPIO.wait_for_edge(PIN_BUTTON, GPIO.RISING, bouncetime=100)
|
||||||
|
|
||||||
|
|
||||||
|
def signal_hook(running=True):
|
||||||
|
while running:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
running = False
|
||||||
|
pygame.quit()
|
||||||
|
elif event.type == pygame.KEYDOWN and event.key == pygame.K_f:
|
||||||
|
pygame.display.toggle_fullscreen()
|
||||||
|
|
||||||
|
def run():
|
||||||
|
config = get_config()
|
||||||
|
pygame.init()
|
||||||
|
_thread.start_new_thread(signal_hook, ())
|
||||||
|
screen = pygame.display.set_mode((config.WIDTH, config.HEIGHT), 0, 0)
|
||||||
|
qr_img = pygame.image.load(config.qr_path).convert()
|
||||||
|
|
||||||
|
while 1:
|
||||||
|
LOGGER.info("Starting...")
|
||||||
|
while 1:
|
||||||
|
display_qr(screen, qr_img)
|
||||||
|
io_remote()
|
||||||
|
photo_path = get_file_name(prefix=config.prefix, path=config.photo_folder)
|
||||||
|
|
||||||
|
|
||||||
|
LOGGER.info(photo_path)
|
||||||
|
# Capture photo
|
||||||
|
try:
|
||||||
|
subprocess.run(
|
||||||
|
[
|
||||||
|
"gphoto2",
|
||||||
|
"--capture-image-and-download",
|
||||||
|
"--camera='Canon EOS 350D (normal mode)'",
|
||||||
|
"--filename={}".format(photo_path),
|
||||||
|
"--force-overwrite",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
LOGGER.info("Failed to capture image.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
img = load_image(photo_path)
|
||||||
|
display_image(screen, img, config.width, config.height)
|
||||||
|
display_text(
|
||||||
|
screen, "Zuerst das Vergnügen, dann der Upload in die cloud...", size=50
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
LOGGER.info("Failed to display image.")
|
||||||
|
pass
|
||||||
|
|
||||||
|
uploader.sync_photo(photo_path="/Users/rootrapp/Downloads/Screenshot 2023-06-19 at 18-43-27 QLC Quick Beginner Overview.png")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
|
@ -1,17 +1,22 @@
|
||||||
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
from webdav3.client import Client
|
from webdav3.client import Client
|
||||||
|
|
||||||
from xmlrpc.client import DateTime
|
from xmlrpc.client import DateTime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def sync_photo(photo_path):
|
def sync_photo(photo_path):
|
||||||
# hochladen des bildes
|
# hochladen des bildes
|
||||||
print("Uploading file..")
|
LOGGER.info("Uploading file..")
|
||||||
print(os.path.isfile(photo_path))
|
LOGGER.info(os.path.isfile(photo_path))
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["rclone", "copy", "{}".format(photo_path), "https://cloud.bauhaeusle.de/remote.php/dav/files/admin"]
|
["rclone", "copy", "{}".format(photo_path), "https://cloud.bauhaeusle.de/remote.php/dav/files/admin"]
|
||||||
)
|
)
|
||||||
print("photo uploaded!")
|
LOGGER.info("photo uploaded!")
|
||||||
|
|
||||||
|
|
||||||
def sync_phot2(photo_path):
|
def sync_phot2(photo_path):
|
||||||
|
@ -26,6 +31,5 @@ def sync_phot2(photo_path):
|
||||||
#client.session.auth(...) # To set proxy auth directly into the session (Optional)
|
#client.session.auth(...) # To set proxy auth directly into the session (Optional)
|
||||||
|
|
||||||
client.upload_sync(remote_path="BestOf/Fotobox", local_path=photo_path)
|
client.upload_sync(remote_path="BestOf/Fotobox", local_path=photo_path)
|
||||||
sync_photo(photo_path="/Users/rootrapp/Downloads/Screenshot 2023-06-19 at 18-43-27 QLC Quick Beginner Overview.png")
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue