Files
beyond-obs/main.py

91 lines
2.3 KiB
Python

from bottle import route, run, template, static_file
tpl_sigle_card = """
<!DOCTYPE html>
<html>
<head>
<title>{{ image }}</title>
<meta http-equiv="refresh" content="30">
</head>
<body>
<img src="/results/{{ image }}" alt="My Image">
</body>
</html>
"""
tpl_slideshow = """
<!DOCTYPE html>
<html>
<head>
<title>123</title>
</head>
<body>
<img src="/results/{{chars_list[-1]}}-{{scene}}.png" alt="My Image" />
<script>
// array of image URLs to iterate over
const imageUrls = [
% for char in chars_list:
'/results/{{char}}-{{scene}}.png',
% end
% if scene == "main":
'/results/transparent.png',
'/results/transparent.png',
'/results/transparent.png',
'/results/transparent.png'
% end
];
// get the img element from the HTML
const img = document.querySelector('img');
let index = 0;
function preloadImage(url) {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => resolve(url);
img.onerror = reject;
img.src = url;
});
}
function changeImage() {
// preload the next image
const nextIndex = (index + 1) % imageUrls.length;
preloadImage(imageUrls[nextIndex]).then(() => {
// set the img src to the next image URL
img.src = imageUrls[nextIndex];
// increment the index
index = nextIndex;
});
}
setInterval(changeImage, {{ int(timeout) * 1000 }});
</script>
</body>
</html>
"""
@route('/<scene>/slideshow/<timeout>/')
def slideshow(scene, timeout):
chars_list = [
'deyan',
'militsa',
'vevel',
'nivenna',
'milosh',
'darpa'
]
return template(tpl_slideshow, scene=scene, chars_list=chars_list, timeout=timeout)
@route('/<scene>/<char_name>/')
def index(scene, char_name):
image = f"{char_name}-{scene}.png"
return template(tpl_sigle_card, image=image)
@route('/results/<filename>')
def server_static(filename):
return static_file(filename, root='results')
run(host='0.0.0.0', port=8080)