halb produktiv

This commit is contained in:
root 2017-10-22 19:19:13 +02:00
parent 76f3b1780f
commit 2f087955e6
31 changed files with 132 additions and 52 deletions

0
.stfolder Normal file
View File

16
broadcast.py Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/python3
import json
import socket
UDP_IP = "255.255.255.255"
UDP_PORT = 32145
MESSAGE = {"subject": "Fotobox Broadcast", "port": 80}
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
data = json.dumps(MESSAGE, indent=4, sort_keys=True)
data = data.encode("UTF-8")
sock.sendto(data, (UDP_IP, UDP_PORT))

BIN
graphics/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

BIN
graphics/1.xcf Normal file

Binary file not shown.

BIN
graphics/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
graphics/2.xcf Normal file

Binary file not shown.

BIN
graphics/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
graphics/3.xcf Normal file

Binary file not shown.

BIN
graphics/begin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
graphics/begin.xcf Normal file

Binary file not shown.

BIN
graphics/canceled.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
graphics/canceled.xcf Normal file

Binary file not shown.

BIN
graphics/end_no.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
graphics/end_no.xcf Normal file

Binary file not shown.

BIN
graphics/end_yes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
graphics/end_yes.xcf Normal file

Binary file not shown.

BIN
graphics/info.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
graphics/info.xcf Normal file

Binary file not shown.

BIN
graphics/info2.xcf Normal file

Binary file not shown.

BIN
graphics/keypad.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
graphics/loading.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

BIN
graphics/loading.xcf Normal file

Binary file not shown.

BIN
graphics/no.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
graphics/saved.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
graphics/saved.xcf Normal file

Binary file not shown.

BIN
graphics/yes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

41
onlineconfig.py Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/python3
import netifaces
import urllib.request
import json
import os
API_URL = "http://fotobox.online:8888/api"
BASE_PATH = "/var/lib/photobox"
MAC_INTERFACE = "eth0"
FOTOBOX_KEY = "eDAOMohrcJY3"
CONFIG_PATH = "%s/config.json" % (BASE_PATH, )
def getHwAddr(ifname):
return netifaces.ifaddresses(ifname)[netifaces.AF_LINK][0]["addr"]
mac_address = getHwAddr(MAC_INTERFACE)
url = "%s/fotobox/config/%s/%s/" % (API_URL, mac_address, FOTOBOX_KEY)
print(url)
reply = urllib.request.urlopen(url).read()
reply = reply.decode("UTF-8")
reply = json.loads(reply)
reply = json.dumps(reply, sort_keys=True, indent=4)
print(reply)
try:
os.makedirs(BASE_PATH)
except OSError:
pass
open(CONFIG_PATH, "w+").write(reply)

View File

@ -8,11 +8,12 @@ from shutil import copyfile
from math import floor from math import floor
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
import traceback
import picamera import picamera
import pygame import pygame
import random import random
import time import time
import json
@ -41,10 +42,6 @@ def monotonic_time():
os.chdir(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
# CONFIGURATION # CONFIGURATION
WIDTH = 800 WIDTH = 800
HEIGHT = 480 HEIGHT = 480
@ -56,13 +53,18 @@ OVERLAY_ALPHA = 64
COLOR_BACK = pygame.Color(0, 0, 0) COLOR_BACK = pygame.Color(0, 0, 0)
COLOR_FLASH = pygame.Color(255, 255, 255) COLOR_FLASH = pygame.Color(255, 255, 255)
GRAPHICS_DIR = "./graphics" GRAPHICS_DIR = "./graphics"
IMAGE_DIR = "/var/www/html/current_images" BASE_PATH = "/var/lib/photobox"
COUNTDOWN = 3 COUNTDOWN = 3
SHOT_COUNT = 3 SHOT_COUNT = 3
BORDER = 10 BORDER = 10
THUMB_WIDTH = int((800 - BORDER) / SHOT_COUNT - BORDER) THUMB_WIDTH = int((800 - BORDER) / SHOT_COUNT - BORDER)
THUMB_HEIGHT = int(THUMB_WIDTH / 1.333) THUMB_HEIGHT = int(THUMB_WIDTH / 1.333)
CONFIG_LOCATION = "%s/config.json" % (BASE_PATH, )
os.chdir(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
@ -71,29 +73,6 @@ session_start = monotonic_time()
# CREATE DIRECTORIES
try:
os.makedirs(GRAPHICS_DIR)
except OSError:
pass
try:
os.makedirs(IMAGE_DIR)
except OSError:
pass
try:
os.makedirs(IMAGE_DIR + "/original")
except OSError:
pass
try:
os.makedirs(IMAGE_DIR + "/todo")
except OSError:
pass
# INIT GPIO # INIT GPIO
GPIO.setmode(GPIO.BOARD) GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False) GPIO.setwarnings(False)
@ -116,6 +95,7 @@ GPIO.output(7, GPIO.LOW)
# INIT PYGAME # INIT PYGAME
pygame.init() pygame.init()
pygame.mixer.quit()
pygame.mouse.set_visible(False) pygame.mouse.set_visible(False)
screen = pygame.display.set_mode((WIDTH,HEIGHT)) screen = pygame.display.set_mode((WIDTH,HEIGHT))
@ -384,9 +364,22 @@ def saveImages(choices):
for i in range(0, SHOT_COUNT): for i in range(0, SHOT_COUNT):
if choices[i] > 0: if choices[i] > 0:
print(" saving image #%s" % i) print(" saving image #%s" % i)
EVENT_PATH = "%s/events/%s" % (BASE_PATH, EVENT_ID)
try:
os.makedirs(EVENT_PATH + "/original")
except OSError:
pass
try:
os.makedirs(EVENT_PATH + "/todo")
except OSError:
pass
filename = "%s-%s-session_age=%05d.jpg" % (local.strftime("%Y%m%dT%H:%M:%S.%f%z"), i, session_age) filename = "%s-%s-session_age=%05d.jpg" % (local.strftime("%Y%m%dT%H:%M:%S.%f%z"), i, session_age)
os.rename("tmp%s.jpg" % i, IMAGE_DIR + "/original/" + filename) os.rename("tmp%s.jpg" % i, EVENT_PATH + "/original/" + filename)
copyfile(IMAGE_DIR + "/original/" + filename, IMAGE_DIR + "/todo/" + filename) copyfile(EVENT_PATH + "/original/" + filename, EVENT_PATH + "/todo/" + filename)
# show message # show message
screen.fill(COLOR_BACK) screen.fill(COLOR_BACK)
@ -396,11 +389,31 @@ def saveImages(choices):
def loadConfig():
global EVENT_ID
try:
if os.path.isfile(CONFIG_LOCATION):
config = open(CONFIG_LOCATION, "r").read()
config = json.loads(config)
EVENT_ID = int(config["id"])
except:
traceback.print_exc()
EVENT_ID = -1
EVENT_ID = -1
while 1: while 1:
waitForBegin() waitForBegin()
makePhotos() makePhotos()
(choices, save) = chooseImages() (choices, save) = chooseImages()
loadConfig()
if save: if save:
saveImages(choices); saveImages(choices);
else: else:

BIN
tmp0.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

BIN
tmp2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

View File

@ -2,7 +2,7 @@
INTERVAL="10" INTERVAL="10"
FAILURE_PAUSE="10" FAILURE_PAUSE="10"
LOCAL_FILES="/var/www/html/current_images" BASE_PATH="/var/lib/photobox"
BASE_URL="https://fotobox.online/upload" BASE_URL="https://fotobox.online/upload"
#BASE_URL="http://fotobox.online:8888/upload" #BASE_URL="http://fotobox.online:8888/upload"
@ -11,47 +11,57 @@ BASE_URL="https://fotobox.online/upload"
FOTOBOX_ID="1" FOTOBOX_ID="1"
FOTOBOX_KEY="eDAOMohrcJY3" FOTOBOX_KEY="eDAOMohrcJY3"
EVENT_ID="20"
cd "$BASE_PATH/events"
mkdir -p "$LOCAL_FILES/todo" 2> /dev/null
mkdir -p "$LOCAL_FILES/upload" 2> /dev/null
mkdir -p "$LOCAL_FILES/lowres" 2> /dev/null
while true; do while true; do
date=$(date +'%Y-%m-%d %H:%M:%S') date=$(date +'%Y-%m-%d %H:%M:%S')
cd "$LOCAL_FILES/todo" todos="$(ls ./*/todo/* 2> /dev/null)"
todos="$(ls ./)"
if [ "$todos" != "" ]; then if [ "$todos" != "" ]; then
echo "$date: uploading files:" echo -e "= CONVERTING ==================================\n"
for todo in $todos; do for todo in $todos; do
echo "converting..." echo "CONVERTING: $todo"
convert "$todo" -resize 1000x -quality 0.7 "../lowres/$todo" && cp "../lowres/$todo" "../upload/$todo" && rm -f "$todo"
event_id=$(echo "$todo" | cut -d'/' -f2)
filename=$(echo "$todo" | cut -d'/' -f4)
mkdir -p "./$event_id/lowres" 2> /dev/null
mkdir -p "./$event_id/upload" 2> /dev/null
lowres="./$event_id/lowres/$filename"
upload="./$event_id/upload/$filename"
( convert "$todo" -resize 1000x -quality 0.7 "$lowres" && cp "$lowres" "$upload" && rm -f "$todo" && echo "OK" ) || echo "FAIL!"
echo ""
done done
echo ""
fi fi
cd "$LOCAL_FILES/upload" uploads="$(ls ./*/upload/* 2> /dev/null)"
uploads="$(ls ./)"
if [ "$uploads" != "" ]; then if [ "$uploads" != "" ]; then
echo "$date: uploading files:" echo -e "= UPLOADING ===================================\n"
for upload in $uploads; do for upload in $uploads; do
echo "uploading..." echo "UPLOADING: $upload"
event_id=$(echo "$upload" | cut -d'/' -f2)
filename=$(echo "$upload" | cut -d'/' -f4)
timestamp_fotobox=$(date +'%Y-%m-%dT%H:%M:%S.%N%z') timestamp_fotobox=$(date +'%Y-%m-%dT%H:%M:%S.%N%z')
timestamp_shot=$(basename "$upload" | sed 's|.jpg||g') timestamp_shot=$(basename "$upload" | sed 's|.jpg||g')
url="$BASE_URL/$FOTOBOX_ID/$FOTOBOX_KEY/$EVENT_ID/$timestamp_fotobox/$timestamp_shot/" url="$BASE_URL/$FOTOBOX_ID/$FOTOBOX_KEY/$event_id/$timestamp_fotobox/$timestamp_shot/"
echo "$url" #~ echo "$url"
result=$(curl -s --form "image=@$upload" "$url" 2>&1) result=$(curl -s --form "image=@$upload" "$url" 2>&1)
echo "$result"
if [ "$result" == "OK" ]; then if [ "$result" == "OK" ]; then
rm -f "$upload" ( rm -f "$upload" && echo "OK" ) || echo "FAIL!"
else else
echo "$result"
sleep $FAILURE_PAUSE sleep $FAILURE_PAUSE
fi fi
echo ""
done done
echo ""
fi fi
# SLEEP # SLEEP