simplified template variables
This commit is contained in:
parent
35ee1b06e5
commit
973cce5509
78
game.py
78
game.py
|
@ -15,48 +15,48 @@ config = ConfigParser()
|
||||||
config.read('config.ini')
|
config.read('config.ini')
|
||||||
tz = pytz.timezone(config.get('main', 'timezone'))
|
tz = pytz.timezone(config.get('main', 'timezone'))
|
||||||
|
|
||||||
@app.errorhandler(404)
|
i18n = {
|
||||||
def page_not_found(e):
|
'lang': config.get('i18n', 'lang'),
|
||||||
lang = config.get('i18n', 'lang')
|
'title': config.get('i18n', 'title'),
|
||||||
title = config.get('i18n', 'title')
|
'more': config.get('i18n', 'more'),
|
||||||
url = config.get('main', 'base_url')
|
'desc': config.get('i18n', 'desc'),
|
||||||
theme = config.get('main', 'theme')
|
'questions_prefix': config.get('i18n', 'questions_prefix'),
|
||||||
desc = config.get('i18n', 'desc')
|
'questions_suffix': config.get('i18n', 'questions_suffix'),
|
||||||
return render_template('404.html', title=title, lang=lang, desc=desc, theme=theme, url=url), 404
|
'separator': config.get('i18n', 'separator'),
|
||||||
|
'mailtext': config.get('i18n', 'mail_link'),
|
||||||
@app.errorhandler(500)
|
'helptext': config.get('i18n', 'help_link'),
|
||||||
def internal_server_error(e):
|
'help': config.get('i18n', 'help')
|
||||||
lang = config.get('i18n', 'lang')
|
}
|
||||||
title = config.get('i18n', 'title')
|
conf = {
|
||||||
url = config.get('main', 'base_url')
|
'separator_char': config.get('main', 'separator_char'),
|
||||||
theme = config.get('main', 'theme')
|
'mailto': config.get('main', 'mail'),
|
||||||
desc = config.get('i18n', 'desc')
|
'url': config.get('main', 'base_url'),
|
||||||
return render_template('500.html', title=title, lang=lang, desc=desc, theme=theme, url=url), 500
|
'theme': config.get('main', 'theme'),
|
||||||
|
'animations': config.get('main', 'animations')
|
||||||
@app.route("/")
|
}
|
||||||
def hello():
|
|
||||||
lang = config.get('i18n', 'lang')
|
|
||||||
title = config.get('i18n', 'title')
|
|
||||||
more = config.get('i18n', 'more')
|
|
||||||
desc = config.get('i18n', 'desc')
|
|
||||||
questions_prefix = config.get('i18n', 'questions_prefix')
|
|
||||||
questions_suffix = config.get('i18n', 'questions_suffix')
|
|
||||||
send_questions = config.get('i18n', 'send_questions')
|
|
||||||
separator = config.get('i18n', 'separator')
|
|
||||||
separator_char = config.get('main', 'separator_char')
|
|
||||||
mail = config.get('main', 'mail')
|
|
||||||
mailtext = config.get('i18n', 'mail_link')
|
|
||||||
helptext = config.get('i18n', 'help_link')
|
|
||||||
help = config.get('i18n', 'help')
|
|
||||||
url = config.get('main', 'base_url')
|
|
||||||
theme = config.get('main', 'theme')
|
|
||||||
animations = config.get('main', 'animations')
|
|
||||||
ablines = []
|
|
||||||
|
|
||||||
|
def getEpoch():
|
||||||
now = datetime.now(tz=tz)
|
now = datetime.now(tz=tz)
|
||||||
epoch = now.timestamp()
|
epoch = now.timestamp()
|
||||||
epoch = int(epoch)
|
epoch = int(epoch)
|
||||||
|
|
||||||
|
return epoch
|
||||||
|
|
||||||
|
@app.errorhandler(404)
|
||||||
|
def page_not_found(e):
|
||||||
|
epoch = getEpoch()
|
||||||
|
return render_template('404.html', config=conf, i18n=i18n, epoch=epoch), 404
|
||||||
|
|
||||||
|
@app.errorhandler(500)
|
||||||
|
def internal_server_error(e):
|
||||||
|
epoch = getEpoch()
|
||||||
|
return render_template('500.html', config=conf, i18n=i18n, epoch=epoch), 500
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def hello():
|
||||||
|
ablines = []
|
||||||
|
epoch = getEpoch()
|
||||||
|
|
||||||
lines = getContent()
|
lines = getContent()
|
||||||
while len(lines) < 2:
|
while len(lines) < 2:
|
||||||
print('Error reading content')
|
print('Error reading content')
|
||||||
|
@ -64,7 +64,7 @@ def hello():
|
||||||
lines = getContent()
|
lines = getContent()
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
ab = line.split(separator_char)
|
ab = line.split(conf['separator_char'])
|
||||||
ablines.append(
|
ablines.append(
|
||||||
{'A': str(ab[0]), 'B': str(ab[1])}
|
{'A': str(ab[0]), 'B': str(ab[1])}
|
||||||
)
|
)
|
||||||
|
@ -72,7 +72,7 @@ def hello():
|
||||||
with open("ab.txt", "r") as f:
|
with open("ab.txt", "r") as f:
|
||||||
num_lines = sum(1 for _ in f)
|
num_lines = sum(1 for _ in f)
|
||||||
|
|
||||||
return render_template('index.html', title=title, separator=separator, content=ablines, num_lines=num_lines, epoch=epoch, mailto=mail, more=more, questions_prefix=questions_prefix, questions_suffix=questions_suffix, send_questions=send_questions, lang=lang, url=url, desc=desc, theme=theme, mailtext=mailtext, helptext=helptext, help=help, animations=animations)
|
return render_template('index.html', content=ablines, config=conf, i18n=i18n, num_lines=num_lines, epoch=epoch)
|
||||||
|
|
||||||
def getContent():
|
def getContent():
|
||||||
lines = [a.strip() for a in open("ab.txt", "r").readlines()]
|
lines = [a.strip() for a in open("ab.txt", "r").readlines()]
|
||||||
|
|
|
@ -9,7 +9,7 @@ function countdown() {
|
||||||
document.getElementById("next").innerHTML = timeleft;
|
document.getElementById("next").innerHTML = timeleft;
|
||||||
}
|
}
|
||||||
timeleft -= 1;
|
timeleft -= 1;
|
||||||
}, 1000);
|
}, 750);
|
||||||
}
|
}
|
||||||
|
|
||||||
function autoReload() {
|
function autoReload() {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
{%- if theme == "light" %}
|
{%- if theme == "light" %}
|
||||||
<html lang="{{ lang }}" data-theme="light">
|
<html lang="{{ i18n.lang }}" data-theme="light">
|
||||||
{%- else %}
|
{%- else %}
|
||||||
<html lang="{{ lang }}" data-theme="dark">
|
<html lang="{{ i18n.lang }}" data-theme="dark">
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
<script type="text/javascript" src="/js/shortcut.js?t={{ epoch }}"></script>
|
<script type="text/javascript" src="/js/shortcut.js?t={{ epoch }}"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="/css/base.css?t={{ epoch }}">
|
<link rel="stylesheet" type="text/css" href="/css/base.css?t={{ epoch }}">
|
||||||
<link rel="stylesheet" type="text/css" href="/css/colors.css?t={{ epoch }}">
|
<link rel="stylesheet" type="text/css" href="/css/colors.css?t={{ epoch }}">
|
||||||
{%- if animations == "1" or animations == "true" %}
|
{%- if config.animations == "1" or config.animations == "true" %}
|
||||||
<link rel="stylesheet" type="text/css" href="/css/animations.css?t={{ epoch }}">
|
<link rel="stylesheet" type="text/css" href="/css/animations.css?t={{ epoch }}">
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="{{ url_for('static', filename='apple-touch-icon.png') }}">
|
<link rel="apple-touch-icon" sizes="180x180" href="{{ url_for('static', filename='apple-touch-icon.png') }}">
|
||||||
|
@ -24,17 +24,17 @@
|
||||||
<meta name="theme-color" content="#ffffff">
|
<meta name="theme-color" content="#ffffff">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
<meta name="robots" content="noindex, nofollow">
|
<meta name="robots" content="noindex, nofollow">
|
||||||
<meta property="og:title" content="{{ title }}">
|
<meta property="og:title" content="{{ i18n.title }}">
|
||||||
<meta property="og:site_name" content="{{ title }}">
|
<meta property="og:site_name" content="{{ i18n.title }}">
|
||||||
<meta property="og:url" content="{{ url }}">
|
<meta property="og:url" content="{{ config.url }}">
|
||||||
<meta property="og:description" content="{{ desc }}">
|
<meta property="og:description" content="{{ i18n.desc }}">
|
||||||
<meta property="og:type" content="website">
|
<meta property="og:type" content="website">
|
||||||
<meta property="og:image" content="{{ url_for('static', filename='ab.jpg') }}">
|
<meta property="og:image" content="{{ url_for('static', filename='ab.jpg') }}">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<div id="header">{{ title }}</div>
|
<div id="header">{{ i18n.title }}</div>
|
||||||
<hr>
|
<hr>
|
||||||
{%- block main %}
|
{%- block main %}
|
||||||
{%- endblock %}
|
{%- endblock %}
|
||||||
|
|
|
@ -15,19 +15,19 @@
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
<div id="questions">
|
<div id="questions">
|
||||||
{{ questions_prefix }} {{ num_lines }} {{ questions_suffix }}
|
{{ i18n.questions_prefix }} {{ num_lines }} {{ i18n.questions_suffix }}
|
||||||
<br>
|
<br>
|
||||||
<a href="mailto:{{ mailto }}">{{ mailtext }}</a> -
|
<a href="mailto:{{ config.mailto }}">{{ i18n.mailtext }}</a> -
|
||||||
<a href="#">{{ helptext }}
|
<a href="#">{{ i18n.helptext }}
|
||||||
<div id="help">
|
<div id="help">
|
||||||
{{ help|safe }}
|
{{ i18n.help|safe }}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% include 'toggle.html' %}
|
{% include 'toggle.html' %}
|
||||||
<form action="/" method="get">
|
<form action="/" method="get">
|
||||||
<input type="hidden" name="t" value="{{ epoch }}">
|
<input type="hidden" name="t" value="{{ epoch }}">
|
||||||
<button id="next" type="submit">{{ more }}</button>
|
<button id="next" type="submit">{{ i18n.more }}</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue