Compare commits
2 commits
3e795ccb48
...
03cb915fa5
Author | SHA1 | Date | |
---|---|---|---|
Théophile Bastian | 03cb915fa5 | ||
Théophile Bastian | 88e42032df |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -58,3 +58,4 @@ docs/_build/
|
||||||
# PyBuilder
|
# PyBuilder
|
||||||
target/
|
target/
|
||||||
|
|
||||||
|
venv
|
||||||
|
|
48
sonnette.py
Normal file
48
sonnette.py
Normal 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
15
templates/base.html
Normal 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
24
templates/homepage.html
Normal 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 %}
|
Loading…
Reference in a new issue