diff --git a/.gitignore b/.gitignore index 7f7cccc..5d56b6e 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ docs/_build/ # PyBuilder target/ +venv diff --git a/sonnette.py b/sonnette.py new file mode 100644 index 0000000..88e636b --- /dev/null +++ b/sonnette.py @@ -0,0 +1,43 @@ +""" Sonnetteweb — Enfin une sonnette à l'Arcoloc + +Sonnez via le réseau local. C'est cool, hein ? +""" + +from datetime import datetime, timedelta +from flask import Flask, render_template, request + +app = Flask('sonnetteweb') + + +class Ringer: + _instance = None + + def __init__(self): + self.last_rung = datetime.fromtimestamp(0) + + @staticmethod + def get(): + if Ringer._instance is None: + Ringer._instance = Ringer() + return Ringer._instance + + def ring(self): + if datetime.now() - self.last_rung < timedelta(seconds=5): + return False + self.last_rung = datetime.now() + + print('dring') + return True + + +@app.route('/', methods=['GET', 'POST']) +def view_home(): + context = {} + if request.method == 'POST': + if request.form['ding'] == 'dong': + if Ringer.get().ring(): + context['has_rung'] = True + else: + context['too_much_dring'] = True + + return render_template('homepage.html', **context) diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..c6169fb --- /dev/null +++ b/templates/base.html @@ -0,0 +1,15 @@ + + + + + + + Sonnette de l'Arcoloc + + + + + {% block content %} + {% endblock content %} + + diff --git a/templates/homepage.html b/templates/homepage.html new file mode 100644 index 0000000..ed17464 --- /dev/null +++ b/templates/homepage.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} + +{% block content %} + +

Sonnette de l'Arcoloc

+ +{% if has_rung %} +
+

Dring :)

+
+{% endif %} + +{% if too_much_dring %} +
+

Non mais on est pas sourd·e·s, hein. Nonmaisoh.

+
+{% endif %} + +
+ + +
+ +{% endblock content %}