#!/usr/bin/env python3 from bottle import route, run, static_file, template from os import listdir from os.path import join as pathjoin from random import random, choice # echo -n "["; ls | xargs -I{} echo -n \"{}\",; echo "]" BG_IMAGES = listdir("./static/img/background") news = """ === 2021-03-24 === * TestABC * FooBar === 2020-xx-xx === * Map now available """ @route("/") def index(): return template("html/index.html", **{"player_count": int(random()*20), "max_players": 20, "news": news}) @route("/request") def request_whitelist(): return "ok" @route("/img/bg.png") def random_bg_image(): bg_file = choice(BG_IMAGES) print(bg_file) response = static_file(bg_file, root="static/img/background") response.set_header("Cache-Control", "no-cache") response.set_header("Cache-Control", "no-store") response.set_header("Pragma-Directive", "no-cache") response.set_header("Cache-Directive", "no-cache") response.set_header("Pragma", "no-cache") response.set_header("Expires", "0") return response @route("/") def callback(path): return static_file(path, root="static") run(host="localhost", port=8080)