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')
|
||||
tz = pytz.timezone(config.get('main', 'timezone'))
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
lang = config.get('i18n', 'lang')
|
||||
title = config.get('i18n', 'title')
|
||||
url = config.get('main', 'base_url')
|
||||
theme = config.get('main', 'theme')
|
||||
desc = config.get('i18n', 'desc')
|
||||
return render_template('404.html', title=title, lang=lang, desc=desc, theme=theme, url=url), 404
|
||||
|
||||
@app.errorhandler(500)
|
||||
def internal_server_error(e):
|
||||
lang = config.get('i18n', 'lang')
|
||||
title = config.get('i18n', 'title')
|
||||
url = config.get('main', 'base_url')
|
||||
theme = config.get('main', 'theme')
|
||||
desc = config.get('i18n', 'desc')
|
||||
return render_template('500.html', title=title, lang=lang, desc=desc, theme=theme, url=url), 500
|
||||
|
||||
@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 = []
|
||||
i18n = {
|
||||
'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'),
|
||||
'separator': config.get('i18n', 'separator'),
|
||||
'mailtext': config.get('i18n', 'mail_link'),
|
||||
'helptext': config.get('i18n', 'help_link'),
|
||||
'help': config.get('i18n', 'help')
|
||||
}
|
||||
conf = {
|
||||
'separator_char': config.get('main', 'separator_char'),
|
||||
'mailto': config.get('main', 'mail'),
|
||||
'url': config.get('main', 'base_url'),
|
||||
'theme': config.get('main', 'theme'),
|
||||
'animations': config.get('main', 'animations')
|
||||
}
|
||||
|
||||
def getEpoch():
|
||||
now = datetime.now(tz=tz)
|
||||
epoch = now.timestamp()
|
||||
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()
|
||||
while len(lines) < 2:
|
||||
print('Error reading content')
|
||||
|
@ -64,7 +64,7 @@ def hello():
|
|||
lines = getContent()
|
||||
|
||||
for line in lines:
|
||||
ab = line.split(separator_char)
|
||||
ab = line.split(conf['separator_char'])
|
||||
ablines.append(
|
||||
{'A': str(ab[0]), 'B': str(ab[1])}
|
||||
)
|
||||
|
@ -72,7 +72,7 @@ def hello():
|
|||
with open("ab.txt", "r") as 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():
|
||||
lines = [a.strip() for a in open("ab.txt", "r").readlines()]
|
||||
|
|
|
@ -9,7 +9,7 @@ function countdown() {
|
|||
document.getElementById("next").innerHTML = timeleft;
|
||||
}
|
||||
timeleft -= 1;
|
||||
}, 1000);
|
||||
}, 750);
|
||||
}
|
||||
|
||||
function autoReload() {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<!DOCTYPE html>
|
||||
{%- if theme == "light" %}
|
||||
<html lang="{{ lang }}" data-theme="light">
|
||||
<html lang="{{ i18n.lang }}" data-theme="light">
|
||||
{%- else %}
|
||||
<html lang="{{ lang }}" data-theme="dark">
|
||||
<html lang="{{ i18n.lang }}" data-theme="dark">
|
||||
{%- endif %}
|
||||
|
||||
<head>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<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/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 }}">
|
||||
{%- endif %}
|
||||
<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="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<meta property="og:title" content="{{ title }}">
|
||||
<meta property="og:site_name" content="{{ title }}">
|
||||
<meta property="og:url" content="{{ url }}">
|
||||
<meta property="og:description" content="{{ desc }}">
|
||||
<meta property="og:title" content="{{ i18n.title }}">
|
||||
<meta property="og:site_name" content="{{ i18n.title }}">
|
||||
<meta property="og:url" content="{{ config.url }}">
|
||||
<meta property="og:description" content="{{ i18n.desc }}">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:image" content="{{ url_for('static', filename='ab.jpg') }}">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="content">
|
||||
<div id="header">{{ title }}</div>
|
||||
<div id="header">{{ i18n.title }}</div>
|
||||
<hr>
|
||||
{%- block main %}
|
||||
{%- endblock %}
|
||||
|
|
|
@ -15,19 +15,19 @@
|
|||
{%- endfor %}
|
||||
<div id="footer">
|
||||
<div id="questions">
|
||||
{{ questions_prefix }} {{ num_lines }} {{ questions_suffix }}
|
||||
{{ i18n.questions_prefix }} {{ num_lines }} {{ i18n.questions_suffix }}
|
||||
<br>
|
||||
<a href="mailto:{{ mailto }}">{{ mailtext }}</a> -
|
||||
<a href="#">{{ helptext }}
|
||||
<a href="mailto:{{ config.mailto }}">{{ i18n.mailtext }}</a> -
|
||||
<a href="#">{{ i18n.helptext }}
|
||||
<div id="help">
|
||||
{{ help|safe }}
|
||||
{{ i18n.help|safe }}
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% include 'toggle.html' %}
|
||||
<form action="/" method="get">
|
||||
<input type="hidden" name="t" value="{{ epoch }}">
|
||||
<button id="next" type="submit">{{ more }}</button>
|
||||
<button id="next" type="submit">{{ i18n.more }}</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue