diff --git a/Event.py b/Event.py index eb62265..21937e7 100644 --- a/Event.py +++ b/Event.py @@ -14,6 +14,7 @@ class Event: self.title = data['title'] self.date = datetime.strptime(data['date'], '%Y-%m-%d') self.password = data['password'] + self.gallery = bool(data['gallery']) self.frame_factor = float(data['frame_factor']) if 'frame_factor' in data else 1.0 self.frame_photo_sized = shrink_cover(Image.open("./data/frames/" + data['frame']), PHOTO_WIDTH, PHOTO_HEIGHT) self.frame = pil_image_to_surface(shrink_cover(self.frame_photo_sized, int(WIDTH * self.frame_factor), int(HEIGHT * self.frame_factor))) diff --git a/Fotobox.py b/Fotobox.py index ffcb2df..cfa3cc9 100644 --- a/Fotobox.py +++ b/Fotobox.py @@ -3,9 +3,9 @@ import time from typing import List from PIL import Image + from escpos.escpos import Escpos -from ConsolePrinter import ConsolePrinter -from serial import SerialException +from escpos.printer import Usb from Event import Event, load_event from Photo import Photo @@ -137,20 +137,21 @@ class Fotobox: elif self._printer is not None and not self._printed and PRINT_RECT.collidepoint(event.pos): print("PRINT") try: - self._printer.set(align='center', font='b', width=2, height=2) - self._printer.text("Fotobox\n") self._printer.set(align='center', font='a', width=1, height=1) + self._printer.text("Fotobox\n") + url = "http%s://%s" % ('s' if HTTPS else '', DOMAIN) if self._event is not None: - self._printer.text(self._event.date.strftime("%d.%m.%Y") + "\n") self._printer.text(self._event.title + "\n") - self._printer.text(self._event.url_without_protocol + "\n") - self._printer.text("Passwort: " + self._event.password + "\n") - else: - self._printer.text(datetime.now().strftime("%d.%m.%Y") + "\n") - self._printer.text(self._idle_url_without_protocol + "\n") - self._printer.qr(self._choice.urlWithProtocol, center=True) - self._printer.text(self._choice.urlWithoutProtocol) - self._printer.cut() + self._printer.text(self._event.date.strftime("%d.%m.%Y") + "\n") + if self._event.gallery: + self._printer.text(self._event.url_without_protocol + "\n") + self._printer.text("Passwort: " + self._event.password + "\n") + self._printer.text("Dein Foto findest du hier:\n") + self._printer.qr(self._choice.urlWithProtocol, center=True, size=5) + self._printer.text(url + "\n") + self._printer.text("/p/" + self._choice.code + "\n") + self._printer.text(" \n") + self._printer.text(" \n") self._printed = True except Exception as e: @@ -218,16 +219,19 @@ class Fotobox: photo.prepare(self._event) self._set_state(State.CHOOSE) elif new_state == State.CHOOSE: - self._choice = None + if DEBUG: + self._choice = self._photos[0] + self._set_state(State.QR) + else: + self._choice = None elif new_state == State.QR: self._printed = False try: if self._printer is None or not self._printer.is_online(): - # self._printer = Serial(devfile='/dev/ttyUSB0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1.00, dsrdtr=True) - self._printer = ConsolePrinter() + self._printer = Usb(0x0483, 0x5840, 0, interface=0, out_ep=0x04, in_ep=0x82) self._printer.profile.media['width']['pixels'] = 512 print("Printer AVAILABLE") - except SerialException: + except Exception: self._printer = None print("No printer available") diff --git a/config.py b/config.py index a4f74d0..574ad2e 100644 --- a/config.py +++ b/config.py @@ -8,7 +8,7 @@ from pygame import Surface from pygame.time import Clock from qrcode.main import QRCode -DEBUG: bool = False +DEBUG: bool = True WIDTH: int = 800 HEIGHT: int = 480 @@ -17,9 +17,9 @@ BORDER: int = 10 PHOTO_WIDTH = 2592 PHOTO_HEIGHT = 1944 -SHOOTING_COUNT: int = 2 +SHOOTING_COUNT: int = 1 if DEBUG else 2 SHOOTING_INTERVAL: float = 0 if DEBUG else 1.75 -COUNTDOWN_COUNT: int = 1 if DEBUG else 1 +COUNTDOWN_COUNT: int = 0 if DEBUG else 3 CHOICE_BORDER: int = 5 @@ -135,4 +135,4 @@ def now(): def generate_code(groups: int): - return '-'.join(''.join(random.choices('23456789abcdefghjkmnpqrstuvwxyz', k=4)) for _ in range(groups)) + return '-'.join(''.join(random.choices('23456789ABCDEFGHJKMNPQRSTUVWXYZ', k=4)) for _ in range(groups)) diff --git a/rsync.sh b/rsync.sh index ba8a57d..d8a8f73 100644 --- a/rsync.sh +++ b/rsync.sh @@ -1,38 +1,5 @@ #!/bin/bash -WATCH_DIR="./data/photos/upload" +cd "$(dirname "$0")/data/photos/upload" || exit 1 -if [ ! -d "$WATCH_DIR" ]; then - echo "watch dir not found: $WATCH_DIR" - exit 1 -fi - -UPLOAD_URL="https://fotobox.online/upload" - -FOTOBOX_KEY="bla..." # TODO - -SLEEP_INTERVAL=10 - -while true; do - for filepath in "$WATCH_DIR"/*; do - [ -e "$filepath" ] || continue - - filename=$(basename "$filepath") - filesize=$(stat -c %s "$filepath") - - echo "uploading: $filepath" - response=$(curl -s -w "\n%{http_code}" -F "file=@${filepath}" -F "filename=${filename}" -F "fotoboxKey=${FOTOBOX_KEY}" "$UPLOAD_URL") - body=$(echo "$response" | head -n 1) - status=$(echo "$response" | tail -n 1) - - expected="Fotobox2|||${filename}|||${filesize}" - - if [ "$status" -eq 200 ] && [ "$body" = "$expected" ]; then - echo "SUCCESS" - rm -f "$filepath" - else - echo "FAILED: CODE=$status, Response=$body" - fi - done - sleep "$SLEEP_INTERVAL" -done +rsync -a ./* fotobox@mc.ph87.de:/srv/fotobox.online/html/p/