Initial commit
This commit is contained in:
commit
46b2dbf4f3
9 changed files with 660 additions and 0 deletions
34
web_view.py
Executable file
34
web_view.py
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
"""Web page to show upcoming events."""
|
||||
|
||||
from datetime import date, datetime, timezone
|
||||
|
||||
from flask import Flask, render_template
|
||||
|
||||
from agenda import get_data
|
||||
|
||||
app = Flask(__name__)
|
||||
app.debug = True
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index() -> str:
|
||||
"""Index page."""
|
||||
data = get_data()
|
||||
now = datetime.now()
|
||||
today = now.date()
|
||||
now_utc = datetime.now(timezone.utc)
|
||||
|
||||
def days_hours(when: datetime) -> str:
|
||||
delta = when - (now if when.tzinfo is None else now_utc)
|
||||
return f"{delta.days:>5,d} days {delta.seconds // 3600:>2.0f} hours"
|
||||
|
||||
def days(when: date) -> str:
|
||||
return " today" if when == today else f"{(when - today).days:>5,d} days"
|
||||
|
||||
return render_template("index.html", days=days, days_hours=days_hours, **data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0")
|
||||
Loading…
Add table
Add a link
Reference in a new issue