Last active
July 5, 2017 16:27
-
-
Save muellermartin/29c46dd8247e53ea1313cbc942fefe9f to your computer and use it in GitHub Desktop.
sinddiewahlergebnisseschonraus.martin-m.org – Repository: https://git.wiai.de/mmueller/sinddiewahlergebnisseschonraus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flipflop import WSGIServer | |
app = Flask(__name__) | |
@app.route("/") | |
def hello_world(): | |
with open("/var/www/sinddiewahlergebnisseschonraus.martin-m.org/status.txt", "r") as f: | |
status = f.read() | |
html = """\ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>WIAI 2017</title> | |
</head> | |
<body> | |
<h1>{status}</h1> | |
<script> | |
var status = document.querySelectorAll("h1")[0].innerHTML; | |
if (status === "Ja!") { | |
var audio = new Audio("https://www.myinstants.com/media/sounds/alarm.MP3"); | |
audio.play(); | |
} | |
var refresh = setInterval(function() { | |
location.reload(true); | |
}, 3000); | |
</script> | |
</body> | |
</html> | |
""" | |
return html.replace("{status}", "Nein." if status == "0" else "Ja!") | |
@app.route("/test") | |
def test(): | |
return "A" | |
if __name__ == "__main__": | |
#app.run(host="0.0.0.0") | |
WSGIServer(app).run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server.document-root = "/var/www/sinddiewahlergebnisseschonraus.martin-m.org/htdocs" | |
fastcgi.server = ( | |
"/" => ( | |
"python" => ( | |
"bin-path" => "/var/www/sinddiewahlergebnisseschonraus.martin-m.org/py/bin/python3 /var/www/sinddiewahlergebnisseschonraus.martin-m.org/app.py", | |
"socket" => "/tmp/sinddiewahlergebnisseschonraus.martin-m.org.sock", | |
"check-local" => "disable", | |
"max-procs" => 1, | |
"fix-root-scriptname" => "enable" | |
) | |
) | |
) | |
compress.cache-dir = var.cachedir + "/sinddiewahlergebnisseschonraus.martin-m.org/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import urllib.request | |
import time | |
site = "https://www.uni-bamberg.de/abt-studium/hochschulwahlen/" | |
#site = "http://sinddiewahlergebnisseschonraus.martin-m.org/test" | |
result = None | |
changed = False | |
while not changed: | |
with urllib.request.urlopen(site) as f: | |
result_new = f.read() | |
if result is not None and result != result_new: | |
status = "1" | |
changed = True | |
else: | |
status = "0" | |
result = result_new | |
with open('status.txt', 'w') as f: | |
f.write(status) | |
time.sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment