Compare commits

...

2 commits

Author SHA1 Message Date
Théophile Bastian 03cb915fa5 Add actual ringing 2018-02-06 01:42:11 +01:00
Théophile Bastian 88e42032df Minimal first version
Currently prints "dring" to stdout, and does not ring.
2018-02-05 23:25:32 +01:00
4 changed files with 88 additions and 0 deletions

1
.gitignore vendored
View file

@ -58,3 +58,4 @@ docs/_build/
# PyBuilder
target/
venv

48
sonnette.py Normal file
View file

@ -0,0 +1,48 @@
""" 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
import subprocess
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!')
subprocess.run(['bash',
'-c',
'mplayer -ao alsa:device=hw=1.0 ringtone.ogg &'])
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)

15
templates/base.html Normal file
View file

@ -0,0 +1,15 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Sonnette de l'Arcoloc</title>
<meta name="author" content="Arcoloc.eu">
<!-- <link rel="stylesheet" href="static/style.css"> -->
</head>
<body>
{% block content %}
{% endblock content %}
</body>
</html>

24
templates/homepage.html Normal file
View file

@ -0,0 +1,24 @@
{% extends "base.html" %}
{% block content %}
<h1>Sonnette de l'Arcoloc</h1>
{% if has_rung %}
<div id="hasrung">
<p>Dring :)</p>
</div>
{% endif %}
{% if too_much_dring %}
<div id="toomuch">
<p>Non mais on est pas sourd·e·s, hein. Nonmaisoh.</p>
</div>
{% endif %}
<form method="post">
<input type="hidden" name='ding' value='dong' />
<input type="submit" value="Dring !" />
</form>
{% endblock content %}