working slideshow

This commit is contained in:
2023-06-07 12:27:52 +03:00
parent 309d351196
commit f8469698ad
2 changed files with 62 additions and 2 deletions

View File

@@ -8,3 +8,4 @@ services:
- .:/code
ports:
- "127.0.0.1:8080:8080"
restart: always

63
main.py
View File

@@ -1,6 +1,6 @@
from bottle import route, run, template, static_file
tpl = """
tpl_sigle_card = """
<!DOCTYPE html>
<html>
<head>
@@ -13,10 +13,69 @@ tpl = """
</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
];
// 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, image=image)
return template(tpl_sigle_card, image=image)
@route('/results/<filename>')
def server_static(filename):