parent
895bf7c972
commit
fcf935271c
|
@ -35,7 +35,7 @@ from . import (
|
|||
uk_holiday,
|
||||
waste_schedule,
|
||||
)
|
||||
from .types import Event
|
||||
from .types import Event, StrDict
|
||||
|
||||
here = dateutil.tz.tzlocal()
|
||||
|
||||
|
@ -128,9 +128,27 @@ def hide_markets_while_away(
|
|||
events.remove(market)
|
||||
|
||||
|
||||
async def get_data(
|
||||
now: datetime, config: flask.config.Config
|
||||
) -> typing.Mapping[str, str | object]:
|
||||
class AgendaData(typing.TypedDict, total=False):
|
||||
"""Agenda Data."""
|
||||
|
||||
now: datetime
|
||||
stock_markets: list[str]
|
||||
rockets: list[thespacedevs.Summary]
|
||||
gwr_advance_tickets: date | None
|
||||
data_gather_seconds: float
|
||||
stock_market_times_seconds: float
|
||||
timings: list[tuple[str, float]]
|
||||
events: list[Event]
|
||||
accommodation_events: list[Event]
|
||||
gaps: list[StrDict]
|
||||
sunrise: datetime
|
||||
sunset: datetime
|
||||
last_week: date
|
||||
two_weeks_ago: date
|
||||
errors: list[tuple[str, Exception]]
|
||||
|
||||
|
||||
async def get_data(now: datetime, config: flask.config.Config) -> AgendaData:
|
||||
"""Get data to display on agenda dashboard."""
|
||||
data_dir = config["DATA_DIR"]
|
||||
|
||||
|
@ -176,7 +194,7 @@ async def get_data(
|
|||
stock_market_times = stock_market.open_and_close()
|
||||
stock_market_times_seconds = time() - t0
|
||||
|
||||
reply: dict[str, typing.Any] = {
|
||||
reply: AgendaData = {
|
||||
"now": now,
|
||||
"stock_markets": stock_market_times,
|
||||
"rockets": rockets,
|
||||
|
@ -228,9 +246,6 @@ async def get_data(
|
|||
events += hn.whoishiring(last_year, next_year)
|
||||
events += carnival.rio_carnival_events(last_year, next_year)
|
||||
|
||||
if config["HIDE_MARKETS_WHILE_AWAY"]:
|
||||
hide_markets_while_away(events, accommodation_events)
|
||||
|
||||
for launch in rockets:
|
||||
dt = None
|
||||
|
||||
|
@ -281,10 +296,10 @@ async def get_data(
|
|||
reply["sunrise"] = sun.sunrise(observer)
|
||||
reply["sunset"] = sun.sunset(observer)
|
||||
reply["events"] = events
|
||||
reply["accommodation_events"] = accommodation_events
|
||||
reply["last_week"] = last_week
|
||||
reply["two_weeks_ago"] = two_weeks_ago
|
||||
|
||||
reply["fullcalendar_events"] = calendar.build_events(events)
|
||||
reply["errors"] = errors
|
||||
|
||||
return reply
|
||||
|
|
|
@ -144,6 +144,13 @@
|
|||
|
||||
<h3>Agenda</h3>
|
||||
|
||||
<div>
|
||||
Markets:
|
||||
<a href="{{ url_for(request.endpoint) }}">Hide while away</a>
|
||||
| <a href="{{ url_for(request.endpoint, markets="show") }}">Show all</a>
|
||||
| <a href="{{ url_for(request.endpoint, markets="hide") }}">Hide all</a>
|
||||
</div>
|
||||
|
||||
{% for event in events if event.as_date >= two_weeks_ago %}
|
||||
{% if loop.first or event.date.year != loop.previtem.date.year or event.date.month != loop.previtem.date.month %}
|
||||
<div class="row mt-2">
|
||||
|
|
18
web_view.py
18
web_view.py
|
@ -23,7 +23,7 @@ import agenda.fx
|
|||
import agenda.holidays
|
||||
import agenda.thespacedevs
|
||||
import agenda.trip
|
||||
from agenda import format_list_with_ampersand, travel, uk_tz
|
||||
from agenda import calendar, format_list_with_ampersand, travel, uk_tz
|
||||
from agenda.types import StrDict, Trip
|
||||
|
||||
app = flask.Flask(__name__)
|
||||
|
@ -72,7 +72,21 @@ async def index() -> str:
|
|||
now = datetime.now()
|
||||
data = await agenda.data.get_data(now, app.config)
|
||||
|
||||
return flask.render_template("index.html", today=now.date(), **data)
|
||||
events = data.pop("events")
|
||||
|
||||
markets_arg = flask.request.args.get("markets")
|
||||
if markets_arg == "hide":
|
||||
events = [e for e in events if e.name != "market"]
|
||||
if markets_arg != "show":
|
||||
agenda.data.hide_markets_while_away(events, data["accommodation_events"])
|
||||
|
||||
return flask.render_template(
|
||||
"index.html",
|
||||
today=now.date(),
|
||||
events=events,
|
||||
fullcalendar_events=calendar.build_events(events),
|
||||
**data,
|
||||
)
|
||||
|
||||
|
||||
@app.route("/launches")
|
||||
|
|
Loading…
Reference in a new issue