from flask import Flask
import fire

from htpy import body, h1, head, html, title, table, tr, td, div, script

app = Flask(__name__)

def run_server(debug=False):
    app.run(debug=debug)

@app.route("/")
def main_page():
    return build_page(None)

def build_page(tt, debug=True):
    _ = tt
    from datetime import datetime

    lines = (
        ("S1", "somewhere", datetime.now().strftime(r"%H:%M:%S"), 4, "3 min"),
        ("S2", "else", datetime.now().strftime(r"%H:%M:%S"), 4, "3 min"),
    )

    retval = html[
        head[title["today's menu"]],
        body[
            div(style="clear: both")[
                h1(style="float: left")["Gröbenzell"],
                h1(style="float: right", id="clock")[datetime.now().strftime(r"%H:%M:%S")],
            ],
            table[
                (tr[
                    (td[element] for element in line)
                ] for line in lines)
            ],
        ]
    ]

    retval = str(retval)

    if debug:
        print(retval)

    return retval

if __name__ == "__main__":
    fire.Fire(run_server)