abgame/game.py

38 lines
1.1 KiB
Python
Executable File

#! /bin/python3
from random import choice
from flask import Flask
app = Flask(__name__,
static_url_path='',
static_folder='static',
template_folder='templates')
@app.route("/")
def hello():
title = 'A oder B'
separator = ' oder '
header = '<html><head><title>'+str(title)+'</title></head><link rel="stylesheet" type="text/css" href="/css/ab.css" /><body><div id="content"><div id="header">'+str(title)+'</div>'
footer = "</div></body></html>"
ablines = ""
lines = getContent()
for line in lines:
ab = line.split(separator)
ablines = '<div class="ab"><div class="a">'+str(ab[0])+'</div><div class="separator">'+str(separator)+'</div><div class="b">'+str(ab[1])+'</div></div>'+ablines
output = header+ablines+footer
return output
def getContent():
lines = [a.strip() for a in open("ab.txt").readlines()]
result = [choice(lines) for a in range(5)]
return result
if __name__ == "__main__":
from waitress import serve
serve(app, host='0.0.0.0', port=5000, ident='a/b game')