working slideshow
This commit is contained in:
@@ -8,3 +8,4 @@ services:
|
|||||||
- .:/code
|
- .:/code
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8080:8080"
|
- "127.0.0.1:8080:8080"
|
||||||
|
restart: always
|
||||||
|
|||||||
63
main.py
63
main.py
@@ -1,6 +1,6 @@
|
|||||||
from bottle import route, run, template, static_file
|
from bottle import route, run, template, static_file
|
||||||
|
|
||||||
tpl = """
|
tpl_sigle_card = """
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@@ -13,10 +13,69 @@ tpl = """
|
|||||||
</html>
|
</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>/')
|
@route('/<scene>/<char_name>/')
|
||||||
def index(scene, char_name):
|
def index(scene, char_name):
|
||||||
image = f"{char_name}-{scene}.png"
|
image = f"{char_name}-{scene}.png"
|
||||||
return template(tpl, image=image)
|
return template(tpl_sigle_card, image=image)
|
||||||
|
|
||||||
@route('/results/<filename>')
|
@route('/results/<filename>')
|
||||||
def server_static(filename):
|
def server_static(filename):
|
||||||
|
|||||||
Reference in New Issue
Block a user