add lang and config py

This commit is contained in:
jr-k 2024-02-19 15:19:04 +01:00
parent 6b18783123
commit cd3bf1a8c4
5 changed files with 56 additions and 9 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ out/
data/uploads/*
!data/uploads/reclame.jpg
data/slideshow.json
config.py

6
config.py.dist Normal file
View File

@ -0,0 +1,6 @@
config = {
"config": False,
"port": 5000,
"reverse_proxy_mode": False,
"lang": "en"
}

3
en.json Normal file
View File

@ -0,0 +1,3 @@
{
"manage.assets.title": "Assets Overview"
}

3
fr.json Normal file
View File

@ -0,0 +1,3 @@
{
"manage_assets_title": "Elements d'affichage"
}

52
obscreen.py Executable file → Normal file
View File

@ -1,15 +1,46 @@
#!/usr/bin/python3
from flask import Flask, render_template, redirect, request, url_for, send_from_directory
import json
import os
import re
import shutil
import subprocess
import sys
from enum import Enum
from flask import Flask, render_template, redirect, request, url_for, send_from_directory
from pysondb import db
from config import config
# <classes>
class ItemType(Enum):
PICTURE = 'picture'
VIDEO = 'video'
URL = 'url'
# </classes>
# <config>
PLAYER_URL = 'http://localhost:{}'.format(config['port'])
DB = db.getDb("data/slideshow.json")
with open('./lang/{}.json'.format(config['lang']), 'r') as file:
LANGDICT = json.load(file)
# </config>
# <reverse-proxy>
if config['reverse_proxy_mode']:
reverse_proxy_config_file = 'system/nginx-reclame'
with open(reverse_proxy_config_file, 'r') as file:
content = file.read()
with open(reverse_proxy_config_file, 'w') as file:
file.write(re.sub(r'proxy_pass .*?;', 'proxy_pass {};'.format(PLAYER_URL), content))
PLAYER_URL = 'http://localhost'
# </reverse-proxy>
# <server>
app = Flask(__name__, template_folder='views', static_folder='data')
port = 5000
if config['debug']:
app.config['TEMPLATES_AUTO_RELOAD'] = True
# </server>
# <xenv>
@ -25,7 +56,8 @@ xenv_presets = f"""
@xset s noblank
@unclutter -display :0 -noevents -grab
@sed -i 's/"exited_cleanly": false/"exited_cleanly": true/' ~/.config/chromium/Default/Preferences
@chromium-browser --disable-features=Translate --ignore-certificate-errors --disable-web-security --disable-restore-session-state --autoplay-policy=no-user-gesture-required --start-maximized --allow-running-insecure-content --remember-cert-error-decisions --disable-restore-session-state --noerrdialogs --kiosk --incognito --window-position=0,0 --display=:0 http://localhost:{port}
#@sleep 10
@chromium-browser --disable-features=Translate --ignore-certificate-errors --disable-web-security --disable-restore-session-state --autoplay-policy=no-user-gesture-required --start-maximized --allow-running-insecure-content --remember-cert-error-decisions --disable-restore-session-state --noerrdialogs --kiosk --incognito --window-position=0,0 --display=:0 {PLAYER_URL}
"""
with open(destination_path, 'w') as file:
file.write(xenv_presets)
@ -49,19 +81,21 @@ def get_ip_address():
# <web>
@app.route('/')
def index():
with open('./data/slideshow.json', 'r') as file:
items = json.load(file)
return render_template('player.jinja.html', port=port, items=json.dumps(items))
return render_template('player.jinja.html', items=json.dumps(DB.getAll()))
@app.route('/slide/default')
def slide_default():
return render_template('default.jinja.html', ipaddr=get_ip_address())
@app.route('/manage')
def manage():
return render_template('manage.jinja.html', ipaddr=get_ip_address(), l=LANGDICT)
@app.errorhandler(404)
def not_found(e):
return send_from_directory('data', '404.html'), 404
# </web>
if __name__ == '__main__':
app.run(host='0.0.0.0', port=port)
app.run(host='0.0.0.0', port=config['port'])