Market display filter

Closes: #158

Closes: #150
This commit is contained in:
Edward Betts 2024-06-18 06:51:45 +01:00
parent 895bf7c972
commit fcf935271c
3 changed files with 47 additions and 11 deletions

View file

@ -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