-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
81 lines (60 loc) · 2.15 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from domain import update_display_record
import flask
from infosys import display
from rabbit import time_background, text_background, display_tasks
from time import sleep
from flask import request, render_template
import os
import socket
import logging
import markdown.extensions.fenced_code
from pygments.formatters import HtmlFormatter
logging.basicConfig(level=logging.INFO)
def create_app(test_config=None):
app = flask.Flask(__name__)
# display = display()
# Try to get the IP address of the device
# Print it to the display and update the DNS record
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = socket.gethostbyname(s.getsockname()[0])
# display.write_text(ip, "split", True)
domain_status = update_display_record(os.environ['NAME'], ip)
if domain_status:
logging.info('Domain Updated')
# display.write_text("Domain Updated", "split", True)
else:
logging.info('Domain Update Failed')
# display.write_text("Domain Update Failed", "split", True)
# Endpoints
@app.route("/")
def index():
formatter = HtmlFormatter(style="emacs",full=True,cssclass="codehilite")
css_string = formatter.get_style_defs()
readme_file = open("README.md", "r")
md_template_string = markdown.markdown(
readme_file.read(), extensions=["fenced_code"]
)
md_css_string = "<style>" + css_string + "</style>"
md_template = md_css_string + md_template_string
return md_template
@app.route("/demo")
def demo():
return render_template("demo.html")
@app.route("/message", methods=["POST"])
def message():
msg = request.form["message"]
effect = request.form["effect"] if "effect" in request.form else "split"
wipe = request.form["wipe"] if "wipe" in request.form else False
if len(msg) > 48:
return "Text too long", 400
text_background.delay(msg, effect, wipe)
return "OK - Task Enqueued", 200
@app.route("/time", methods=["GET"])
def time():
time_background.delay()
return "OK - Task Enqueued", 200
return app
app = create_app()
if __name__ == "__main__":
app.run()