2023-11-07 15:55:05 +00:00
|
|
|
"""Agenda data."""
|
|
|
|
|
|
|
|
import asyncio
|
2023-12-28 20:32:55 +00:00
|
|
|
import itertools
|
2023-11-07 15:55:05 +00:00
|
|
|
import os
|
|
|
|
import typing
|
2023-11-09 16:51:01 +00:00
|
|
|
from datetime import date, datetime, timedelta
|
2024-01-08 15:22:16 +00:00
|
|
|
from time import time
|
2023-11-07 15:55:05 +00:00
|
|
|
|
2023-11-09 16:51:01 +00:00
|
|
|
import dateutil.rrule
|
2023-11-07 15:55:05 +00:00
|
|
|
import dateutil.tz
|
2023-12-07 15:52:48 +00:00
|
|
|
import flask
|
2023-12-05 00:04:56 +00:00
|
|
|
import isodate # type: ignore
|
2023-11-07 15:55:05 +00:00
|
|
|
import lxml
|
|
|
|
import pytz
|
2023-11-08 14:40:07 +00:00
|
|
|
import yaml
|
2024-01-22 14:13:02 +00:00
|
|
|
from dateutil.easter import easter
|
2023-11-07 15:55:05 +00:00
|
|
|
|
|
|
|
from . import (
|
|
|
|
accommodation,
|
|
|
|
birthday,
|
|
|
|
calendar,
|
|
|
|
conference,
|
2023-11-12 18:58:56 +00:00
|
|
|
domains,
|
2023-11-07 15:55:05 +00:00
|
|
|
economist,
|
|
|
|
gwr,
|
2023-12-01 10:35:58 +00:00
|
|
|
hn,
|
2024-01-16 07:42:44 +00:00
|
|
|
holidays,
|
2023-11-21 08:15:16 +00:00
|
|
|
meetup,
|
2023-11-07 15:55:05 +00:00
|
|
|
stock_market,
|
|
|
|
subscription,
|
|
|
|
sun,
|
|
|
|
thespacedevs,
|
|
|
|
travel,
|
|
|
|
uk_holiday,
|
2023-12-26 19:29:07 +00:00
|
|
|
uk_tz,
|
2023-11-07 15:55:05 +00:00
|
|
|
waste_schedule,
|
|
|
|
)
|
2024-01-23 15:58:01 +00:00
|
|
|
from .types import Event, StrDict, Trip
|
2023-12-28 20:32:55 +00:00
|
|
|
|
2023-11-07 15:55:05 +00:00
|
|
|
here = dateutil.tz.tzlocal()
|
|
|
|
|
|
|
|
# deadline to file tax return
|
|
|
|
# credit card expiry dates
|
|
|
|
# morzine ski lifts
|
|
|
|
# chalet availablity calendar
|
|
|
|
|
|
|
|
# starlink visible
|
|
|
|
|
|
|
|
|
|
|
|
def timezone_transition(
|
2023-11-09 16:51:01 +00:00
|
|
|
start: datetime, end: datetime, key: str, tz_name: str
|
2023-11-07 15:55:05 +00:00
|
|
|
) -> list[Event]:
|
|
|
|
"""Clocks changes."""
|
|
|
|
tz = pytz.timezone(tz_name)
|
|
|
|
return [
|
|
|
|
Event(name=key, date=pytz.utc.localize(t).astimezone(tz))
|
|
|
|
for t in tz._utc_transition_times # type: ignore
|
2023-11-09 16:51:01 +00:00
|
|
|
if start <= t <= end
|
2023-11-07 15:55:05 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2023-12-26 19:29:07 +00:00
|
|
|
def midnight(d: date) -> datetime:
|
|
|
|
"""Convert from date to midnight on that day."""
|
|
|
|
return datetime.combine(d, datetime.min.time())
|
|
|
|
|
|
|
|
|
2024-01-22 14:13:02 +00:00
|
|
|
def rio_carnival_events(start_date: date, end_date: date) -> list[Event]:
|
|
|
|
"""List of events for Rio Carnival for each year between start_date and end_date."""
|
|
|
|
events = []
|
|
|
|
for year in range(start_date.year, end_date.year + 1):
|
|
|
|
easter_date = easter(year)
|
|
|
|
carnival_start = easter_date - timedelta(days=51)
|
|
|
|
carnival_end = easter_date - timedelta(days=46)
|
|
|
|
|
|
|
|
# Only include the carnival if it falls within the specified date range
|
|
|
|
if (
|
|
|
|
start_date <= carnival_start <= end_date
|
|
|
|
or start_date <= carnival_end <= end_date
|
|
|
|
):
|
|
|
|
events.append(
|
|
|
|
Event(
|
|
|
|
name="carnival",
|
|
|
|
title="Rio Carnival",
|
|
|
|
date=carnival_start,
|
|
|
|
end_date=carnival_end,
|
|
|
|
url="https://en.wikipedia.org/wiki/Rio_Carnival",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
return events
|
|
|
|
|
|
|
|
|
2023-11-09 16:51:01 +00:00
|
|
|
def dates_from_rrule(
|
|
|
|
rrule: str, start: date, end: date
|
|
|
|
) -> typing.Sequence[datetime | date]:
|
|
|
|
"""Generate events from an RRULE between start_date and end_date."""
|
|
|
|
all_day = not any(param in rrule for param in ["BYHOUR", "BYMINUTE", "BYSECOND"])
|
2023-11-07 15:55:05 +00:00
|
|
|
|
2023-11-09 16:51:01 +00:00
|
|
|
return [
|
2023-12-26 19:29:07 +00:00
|
|
|
i.date() if all_day else uk_tz.localize(i)
|
|
|
|
for i in dateutil.rrule.rrulestr(rrule, dtstart=midnight(start)).between(
|
|
|
|
midnight(start), midnight(end)
|
2023-11-09 16:51:01 +00:00
|
|
|
)
|
|
|
|
]
|
2023-11-07 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def waste_collection_events(data_dir: str) -> list[Event]:
|
|
|
|
"""Waste colllection events."""
|
|
|
|
postcode = "BS48 3HG"
|
|
|
|
uprn = "24071046"
|
|
|
|
|
|
|
|
html = await waste_schedule.get_html(data_dir, postcode, uprn)
|
|
|
|
root = lxml.html.fromstring(html)
|
|
|
|
events = waste_schedule.parse(root)
|
|
|
|
return events
|
|
|
|
|
|
|
|
|
|
|
|
async def bristol_waste_collection_events(
|
|
|
|
data_dir: str, start_date: date
|
|
|
|
) -> list[Event]:
|
|
|
|
"""Waste colllection events."""
|
|
|
|
uprn = "358335"
|
|
|
|
|
|
|
|
return await waste_schedule.get_bristol_gov_uk(start_date, data_dir, uprn)
|
|
|
|
|
|
|
|
|
2023-11-09 23:35:38 +00:00
|
|
|
def get_yaml_event_date_field(item: dict[str, str]) -> str:
|
|
|
|
"""Event date field name."""
|
|
|
|
return (
|
|
|
|
"end_date"
|
|
|
|
if item["name"] == "travel_insurance"
|
|
|
|
else ("start_date" if "start_date" in item else "date")
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-11-10 00:02:22 +00:00
|
|
|
def get_yaml_event_end_date_field(item: dict[str, str]) -> str:
|
|
|
|
"""Event date field name."""
|
|
|
|
return (
|
|
|
|
"end_date"
|
|
|
|
if item["name"] == "travel_insurance"
|
|
|
|
else ("start_date" if "start_date" in item else "date")
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-01-23 15:58:01 +00:00
|
|
|
def read_events_yaml(
|
|
|
|
data_dir: str, start: date, end: date, skip_trips: bool = False
|
|
|
|
) -> list[Event]:
|
2023-11-08 14:40:07 +00:00
|
|
|
"""Read eventes from YAML file."""
|
2023-11-09 16:51:01 +00:00
|
|
|
events: list[Event] = []
|
|
|
|
for item in yaml.safe_load(open(os.path.join(data_dir, "events.yaml"))):
|
2024-01-23 15:58:01 +00:00
|
|
|
if "trip" in item and skip_trips:
|
|
|
|
continue
|
2023-11-10 00:02:22 +00:00
|
|
|
duration = (
|
|
|
|
isodate.parse_duration(item["duration"]) if "duration" in item else None
|
|
|
|
)
|
2023-11-09 16:51:01 +00:00
|
|
|
dates = (
|
|
|
|
dates_from_rrule(item["rrule"], start, end)
|
|
|
|
if "rrule" in item
|
2023-11-09 23:35:38 +00:00
|
|
|
else [item[get_yaml_event_date_field(item)]]
|
2023-11-08 12:48:02 +00:00
|
|
|
)
|
2023-11-09 16:51:01 +00:00
|
|
|
for dt in dates:
|
|
|
|
e = Event(
|
|
|
|
name=item["name"],
|
|
|
|
date=dt,
|
2023-11-09 23:35:38 +00:00
|
|
|
end_date=(
|
2023-11-10 00:02:22 +00:00
|
|
|
dt + duration
|
|
|
|
if duration
|
|
|
|
else (
|
|
|
|
item.get("end_date")
|
|
|
|
if item["name"] != "travel_insurance"
|
|
|
|
else None
|
|
|
|
)
|
2023-11-09 23:35:38 +00:00
|
|
|
),
|
2023-11-09 16:51:01 +00:00
|
|
|
title=item.get("title"),
|
|
|
|
url=item.get("url"),
|
|
|
|
)
|
|
|
|
events.append(e)
|
|
|
|
return events
|
2023-11-08 12:48:02 +00:00
|
|
|
|
|
|
|
|
2024-01-08 15:20:48 +00:00
|
|
|
def find_events_during_stay(
|
2023-12-22 14:47:06 +00:00
|
|
|
accommodation_events: list[Event], markets: list[Event]
|
|
|
|
) -> list[Event]:
|
|
|
|
"""Market events that happen during accommodation stays."""
|
|
|
|
overlapping_markets = []
|
|
|
|
for market in markets:
|
2024-01-08 15:19:20 +00:00
|
|
|
market_date = market.as_date
|
|
|
|
assert isinstance(market_date, date)
|
2023-12-22 14:47:06 +00:00
|
|
|
for e in accommodation_events:
|
2024-01-08 15:19:20 +00:00
|
|
|
start, end = e.as_date, e.end_as_date
|
|
|
|
assert start and end and all(isinstance(i, date) for i in (start, end))
|
2023-12-22 14:47:06 +00:00
|
|
|
# Check if the market date is within the accommodation dates.
|
2024-01-08 15:19:20 +00:00
|
|
|
if start <= market_date <= end:
|
2023-12-22 14:47:06 +00:00
|
|
|
overlapping_markets.append(market)
|
|
|
|
break # Breaks the inner loop if overlap is found.
|
|
|
|
return overlapping_markets
|
|
|
|
|
|
|
|
|
2023-12-28 20:32:55 +00:00
|
|
|
def find_gaps(events: list[Event], min_gap_days: int = 3) -> list[StrDict]:
|
2023-12-26 23:49:55 +00:00
|
|
|
"""Gaps of at least `min_gap_days` between events in a list of events."""
|
|
|
|
# Sort events by start date
|
|
|
|
|
|
|
|
gaps: list[tuple[date, date]] = []
|
|
|
|
previous_event_end = None
|
|
|
|
|
2023-12-28 20:32:55 +00:00
|
|
|
by_start_date = {
|
|
|
|
d: list(on_day)
|
|
|
|
for d, on_day in itertools.groupby(events, key=lambda e: e.as_date)
|
|
|
|
}
|
|
|
|
|
|
|
|
by_end_date = {
|
|
|
|
d: list(on_day)
|
|
|
|
for d, on_day in itertools.groupby(events, key=lambda e: e.end_as_date)
|
|
|
|
}
|
|
|
|
|
2023-12-26 23:49:55 +00:00
|
|
|
for event in events:
|
|
|
|
# Use start date for current event
|
|
|
|
start_date = event.as_date
|
|
|
|
|
|
|
|
# If previous event exists, calculate the gap
|
|
|
|
if previous_event_end:
|
|
|
|
gap_days = (start_date - previous_event_end).days
|
|
|
|
if gap_days >= (min_gap_days + 2):
|
|
|
|
start_end = (
|
|
|
|
previous_event_end + timedelta(days=1),
|
|
|
|
start_date - timedelta(days=1),
|
|
|
|
)
|
|
|
|
gaps.append(start_end)
|
|
|
|
|
|
|
|
# Update previous event end date
|
2023-12-28 20:32:55 +00:00
|
|
|
end = event.end_as_date
|
2023-12-26 23:49:55 +00:00
|
|
|
if not previous_event_end or end > previous_event_end:
|
|
|
|
previous_event_end = end
|
|
|
|
|
2023-12-28 20:32:55 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
"start": gap_start,
|
|
|
|
"end": gap_end,
|
|
|
|
"after": by_start_date[gap_end + timedelta(days=1)],
|
|
|
|
"before": by_end_date[gap_start - timedelta(days=1)],
|
|
|
|
}
|
|
|
|
for gap_start, gap_end in gaps
|
|
|
|
]
|
2023-12-26 23:49:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def busy_event(e: Event) -> bool:
|
|
|
|
"""Busy."""
|
|
|
|
if e.name not in {
|
|
|
|
"event",
|
|
|
|
"accommodation",
|
|
|
|
"conference",
|
|
|
|
"transport",
|
|
|
|
"meetup",
|
2024-01-01 09:41:17 +00:00
|
|
|
"party",
|
2024-01-23 15:58:01 +00:00
|
|
|
"trip",
|
2023-12-26 23:49:55 +00:00
|
|
|
}:
|
|
|
|
return False
|
|
|
|
|
2023-12-31 20:57:54 +00:00
|
|
|
if e.title in ("IA UK board meeting", "Mill Road Winter Fair"):
|
|
|
|
return False
|
|
|
|
|
2023-12-26 23:49:55 +00:00
|
|
|
if e.name == "conference" and not e.going:
|
|
|
|
return False
|
|
|
|
if not e.title:
|
|
|
|
return True
|
|
|
|
if e.title == "LHG Run Club" or "Third Thursday Social" in e.title:
|
|
|
|
return False
|
|
|
|
|
|
|
|
lc_title = e.title.lower()
|
|
|
|
return "rebels" not in lc_title and "south west data social" not in lc_title
|
|
|
|
|
|
|
|
|
2024-01-08 15:22:16 +00:00
|
|
|
async def time_function(
|
|
|
|
name: str,
|
|
|
|
func: typing.Callable[..., typing.Coroutine[typing.Any, typing.Any, typing.Any]],
|
|
|
|
*args,
|
|
|
|
**kwargs,
|
2024-02-18 22:36:15 +00:00
|
|
|
) -> tuple[str, typing.Any, float, Exception | None]:
|
2024-01-08 15:22:16 +00:00
|
|
|
"""Time the execution of an asynchronous function."""
|
2024-02-18 22:36:15 +00:00
|
|
|
start_time, result, exception = time(), None, None
|
|
|
|
try:
|
|
|
|
result = await func(*args, **kwargs)
|
|
|
|
except Exception as e:
|
|
|
|
exception = e
|
2024-01-08 15:22:16 +00:00
|
|
|
end_time = time()
|
2024-02-18 22:36:15 +00:00
|
|
|
return name, result, end_time - start_time, exception
|
2024-01-08 15:22:16 +00:00
|
|
|
|
|
|
|
|
2024-02-21 13:06:40 +00:00
|
|
|
def get_busy_events(
|
2024-01-23 15:58:01 +00:00
|
|
|
today: date, config: flask.config.Config, trips: list[Trip]
|
2024-02-21 13:06:40 +00:00
|
|
|
) -> list[Event]:
|
|
|
|
"""Find busy events from a year ago to two years in the future."""
|
2024-01-23 15:58:01 +00:00
|
|
|
last_year = today - timedelta(days=365)
|
|
|
|
next_year = today + timedelta(days=2 * 365)
|
|
|
|
|
|
|
|
my_data = config["PERSONAL_DATA"]
|
|
|
|
events = read_events_yaml(my_data, last_year, next_year, skip_trips=True)
|
|
|
|
|
|
|
|
for trip in trips:
|
|
|
|
event_type = "trip"
|
|
|
|
if trip.events and not trip.conferences:
|
|
|
|
event_type = trip.events[0]["name"]
|
|
|
|
elif len(trip.conferences) == 1 and trip.conferences[0].get("hackathon"):
|
|
|
|
event_type = "hackathon"
|
|
|
|
events.append(
|
|
|
|
Event(
|
|
|
|
name=event_type,
|
|
|
|
title=trip.title + " " + trip.country_flags,
|
|
|
|
date=trip.start,
|
|
|
|
end_date=trip.end,
|
|
|
|
url=flask.url_for("trip_page", start=trip.start.isoformat()),
|
|
|
|
)
|
|
|
|
)
|
2024-02-21 13:06:40 +00:00
|
|
|
# pprint(events)
|
2024-01-23 15:58:01 +00:00
|
|
|
|
|
|
|
busy_events = [
|
|
|
|
e
|
|
|
|
for e in sorted(events, key=lambda e: e.as_date)
|
|
|
|
if e.as_date > today and e.as_date < next_year and busy_event(e)
|
|
|
|
]
|
|
|
|
|
2024-02-21 13:06:40 +00:00
|
|
|
return busy_events
|
|
|
|
|
|
|
|
|
|
|
|
def weekends(busy_events: list[Event]) -> typing.Sequence[StrDict]:
|
|
|
|
"""Next ten weekends."""
|
|
|
|
today = datetime.today()
|
|
|
|
weekday = today.weekday()
|
|
|
|
|
|
|
|
# Calculate the difference to the next or previous Saturday
|
|
|
|
if weekday == 6: # Sunday
|
|
|
|
start_date = (today - timedelta(days=1)).date()
|
|
|
|
else:
|
|
|
|
start_date = (today + timedelta(days=(5 - weekday))).date()
|
|
|
|
|
|
|
|
weekends_info = []
|
|
|
|
for i in range(52):
|
|
|
|
saturday = start_date + timedelta(weeks=i)
|
|
|
|
sunday = saturday + timedelta(days=1)
|
|
|
|
|
|
|
|
saturday_events = [
|
|
|
|
event
|
|
|
|
for event in busy_events
|
|
|
|
if event.end_date and event.as_date <= saturday <= event.end_as_date
|
|
|
|
]
|
|
|
|
sunday_events = [
|
|
|
|
event
|
|
|
|
for event in busy_events
|
|
|
|
if event.end_date and event.as_date <= sunday <= event.end_as_date
|
|
|
|
]
|
|
|
|
|
|
|
|
weekends_info.append(
|
|
|
|
{"date": saturday, "saturday": saturday_events, "sunday": sunday_events}
|
|
|
|
)
|
|
|
|
|
|
|
|
return weekends_info
|
2024-01-23 15:58:01 +00:00
|
|
|
|
|
|
|
|
2023-12-07 15:52:48 +00:00
|
|
|
async def get_data(
|
|
|
|
now: datetime, config: flask.config.Config
|
|
|
|
) -> typing.Mapping[str, str | object]:
|
2023-11-19 11:42:39 +00:00
|
|
|
"""Get data to display on agenda dashboard."""
|
2023-12-07 15:52:48 +00:00
|
|
|
data_dir = config["DATA_DIR"]
|
2023-11-07 15:55:05 +00:00
|
|
|
|
|
|
|
rocket_dir = os.path.join(data_dir, "thespacedevs")
|
|
|
|
today = now.date()
|
|
|
|
two_weeks_ago = today - timedelta(weeks=2)
|
|
|
|
last_week = today - timedelta(weeks=1)
|
|
|
|
last_year = today - timedelta(days=365)
|
2024-01-01 00:43:09 +00:00
|
|
|
next_year = today + timedelta(days=2 * 365)
|
2023-11-07 15:55:05 +00:00
|
|
|
|
|
|
|
minus_365 = now - timedelta(days=365)
|
|
|
|
plus_365 = now + timedelta(days=365)
|
|
|
|
|
2024-01-08 15:22:16 +00:00
|
|
|
t0 = time()
|
|
|
|
result_list = await asyncio.gather(
|
|
|
|
time_function("gwr_advance_tickets", gwr.advance_ticket_date, data_dir),
|
|
|
|
time_function("backwell_bins", waste_collection_events, data_dir),
|
|
|
|
time_function("bristol_bins", bristol_waste_collection_events, data_dir, today),
|
2023-11-07 15:55:05 +00:00
|
|
|
)
|
2024-01-19 19:53:21 +00:00
|
|
|
rockets = thespacedevs.read_cached_launches(rocket_dir)
|
2023-11-07 15:55:05 +00:00
|
|
|
|
2024-01-08 15:22:16 +00:00
|
|
|
results = {call[0]: call[1] for call in result_list}
|
|
|
|
|
2024-02-18 22:36:15 +00:00
|
|
|
errors = [(call[0], call[3]) for call in result_list if call[3]]
|
|
|
|
|
2024-01-08 15:22:16 +00:00
|
|
|
gwr_advance_tickets = results["gwr_advance_tickets"]
|
|
|
|
|
|
|
|
data_gather_seconds = time() - t0
|
|
|
|
t0 = time()
|
|
|
|
|
|
|
|
stock_market_times = stock_market.open_and_close()
|
|
|
|
stock_market_times_seconds = time() - t0
|
|
|
|
|
2023-12-26 23:49:55 +00:00
|
|
|
reply: dict[str, typing.Any] = {
|
2023-11-07 15:55:05 +00:00
|
|
|
"now": now,
|
2024-01-08 15:22:16 +00:00
|
|
|
"stock_markets": stock_market_times,
|
2024-01-19 19:53:21 +00:00
|
|
|
"rockets": rockets,
|
2023-11-10 23:57:38 +00:00
|
|
|
"gwr_advance_tickets": gwr_advance_tickets,
|
2024-01-08 15:22:16 +00:00
|
|
|
"data_gather_seconds": data_gather_seconds,
|
|
|
|
"stock_market_times_seconds": stock_market_times_seconds,
|
|
|
|
"timings": [(call[0], call[2]) for call in result_list],
|
2023-11-07 15:55:05 +00:00
|
|
|
}
|
|
|
|
|
2023-12-07 15:52:48 +00:00
|
|
|
my_data = config["PERSONAL_DATA"]
|
2023-11-10 10:42:17 +00:00
|
|
|
events = (
|
|
|
|
[
|
|
|
|
Event(name="mothers_day", date=uk_holiday.get_mothers_day(today)),
|
|
|
|
]
|
|
|
|
+ timezone_transition(minus_365, plus_365, "uk_clock_change", "Europe/London")
|
|
|
|
+ timezone_transition(
|
|
|
|
minus_365, plus_365, "us_clock_change", "America/New_York"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-11-19 11:41:42 +00:00
|
|
|
if gwr_advance_tickets:
|
|
|
|
events.append(Event(name="gwr_advance_tickets", date=gwr_advance_tickets))
|
|
|
|
|
2024-01-16 07:42:44 +00:00
|
|
|
us_hols = holidays.us_holidays(last_year, next_year)
|
|
|
|
events += holidays.get_nyse_holidays(last_year, next_year, us_hols)
|
2023-12-23 16:12:49 +00:00
|
|
|
|
2023-12-22 14:47:06 +00:00
|
|
|
accommodation_events = accommodation.get_events(
|
|
|
|
os.path.join(my_data, "accommodation.yaml")
|
|
|
|
)
|
2023-12-09 13:51:24 +00:00
|
|
|
|
2024-01-16 11:35:38 +00:00
|
|
|
holiday_list = holidays.get_all(last_year, next_year, data_dir)
|
2024-01-16 07:42:44 +00:00
|
|
|
events += holidays.combine_holidays(holiday_list)
|
2023-11-07 15:55:05 +00:00
|
|
|
events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml"))
|
2023-12-22 14:47:06 +00:00
|
|
|
events += accommodation_events
|
2023-12-07 15:52:48 +00:00
|
|
|
events += travel.all_events(my_data)
|
2023-11-07 15:55:05 +00:00
|
|
|
events += conference.get_list(os.path.join(my_data, "conferences.yaml"))
|
2024-02-18 22:36:15 +00:00
|
|
|
for key in "backwell_bins", "bristol_bins":
|
|
|
|
if results[key]:
|
|
|
|
events += results[key]
|
2023-11-09 16:51:01 +00:00
|
|
|
events += read_events_yaml(my_data, last_year, next_year)
|
2023-11-07 15:55:05 +00:00
|
|
|
events += subscription.get_events(os.path.join(my_data, "subscriptions.yaml"))
|
2023-11-10 10:42:17 +00:00
|
|
|
events += economist.publication_dates(last_week, next_year)
|
2023-11-21 08:15:16 +00:00
|
|
|
events += meetup.get_events(my_data)
|
2023-12-01 10:35:58 +00:00
|
|
|
events += hn.whoishiring(last_year, next_year)
|
2024-01-22 14:13:02 +00:00
|
|
|
events += rio_carnival_events(last_year, next_year)
|
2023-11-07 15:55:05 +00:00
|
|
|
|
2023-11-12 18:58:56 +00:00
|
|
|
events += domains.renewal_dates(my_data)
|
|
|
|
|
2023-12-22 14:47:06 +00:00
|
|
|
# hide markets that happen while away
|
2024-01-08 15:20:48 +00:00
|
|
|
optional = [
|
|
|
|
e
|
|
|
|
for e in events
|
|
|
|
if e.name == "market" or (e.title and "LHG Run Club" in e.title)
|
|
|
|
]
|
2023-12-30 17:13:46 +00:00
|
|
|
going = [e for e in events if e.going]
|
2023-12-22 14:47:06 +00:00
|
|
|
|
2024-01-08 15:20:48 +00:00
|
|
|
overlapping_markets = find_events_during_stay(
|
|
|
|
accommodation_events + going, optional
|
2023-12-30 17:13:46 +00:00
|
|
|
)
|
2023-12-22 14:47:06 +00:00
|
|
|
for market in overlapping_markets:
|
|
|
|
events.remove(market)
|
|
|
|
|
2024-01-19 19:53:21 +00:00
|
|
|
for launch in rockets:
|
2023-11-25 10:08:49 +00:00
|
|
|
dt = None
|
|
|
|
|
2024-02-11 07:42:45 +00:00
|
|
|
net_precision = launch["net_precision"]
|
|
|
|
skip = {"Year", "Month", "Quarter", "Fiscal Year"}
|
|
|
|
if net_precision == "Day":
|
2024-01-16 15:05:59 +00:00
|
|
|
dt = datetime.strptime(launch["net"], "%Y-%m-%dT%H:%M:%SZ").date()
|
2024-02-11 07:42:45 +00:00
|
|
|
elif (
|
|
|
|
net_precision
|
|
|
|
and net_precision not in skip
|
|
|
|
and "Year" not in net_precision
|
|
|
|
and launch["t0_time"]
|
|
|
|
):
|
2023-11-25 10:08:49 +00:00
|
|
|
dt = pytz.utc.localize(
|
|
|
|
datetime.strptime(launch["net"], "%Y-%m-%dT%H:%M:%SZ")
|
|
|
|
)
|
|
|
|
|
|
|
|
if not dt:
|
2023-11-23 22:05:05 +00:00
|
|
|
continue
|
2023-11-25 10:08:49 +00:00
|
|
|
|
2024-01-16 15:32:39 +00:00
|
|
|
rocket_name = f'{launch["rocket"]}: {launch["mission_name"] or "[no mission]"}'
|
2023-11-25 10:08:49 +00:00
|
|
|
e = Event(name="rocket", date=dt, title=rocket_name)
|
2023-11-23 22:05:05 +00:00
|
|
|
events.append(e)
|
|
|
|
|
2023-12-05 13:59:00 +00:00
|
|
|
events += [Event(name="today", date=today)]
|
2023-12-26 23:49:55 +00:00
|
|
|
|
|
|
|
busy_events = [
|
|
|
|
e
|
|
|
|
for e in sorted(events, key=lambda e: e.as_date)
|
2024-01-01 00:43:09 +00:00
|
|
|
if e.as_date > today and e.as_date < next_year and busy_event(e)
|
2023-12-26 23:49:55 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
gaps = find_gaps(busy_events)
|
|
|
|
|
2023-12-28 20:32:55 +00:00
|
|
|
events += [
|
|
|
|
Event(name="gap", date=gap["start"], end_date=gap["end"]) for gap in gaps
|
|
|
|
]
|
2023-12-26 23:49:55 +00:00
|
|
|
|
|
|
|
# Sort events by their datetime; the "today" event is prioritised
|
|
|
|
# at the top of the list for today. This is achieved by sorting first by
|
|
|
|
# the datetime attribute, and then ensuring that events with the name
|
|
|
|
# "today" are ordered before others on the same date.
|
2023-12-05 13:59:00 +00:00
|
|
|
events.sort(key=lambda e: (e.as_datetime, e.name != "today"))
|
2023-11-07 15:55:05 +00:00
|
|
|
|
2023-12-26 23:49:55 +00:00
|
|
|
reply["gaps"] = gaps
|
|
|
|
|
2023-11-09 16:51:01 +00:00
|
|
|
observer = sun.bristol()
|
|
|
|
reply["sunrise"] = sun.sunrise(observer)
|
|
|
|
reply["sunset"] = sun.sunset(observer)
|
2023-11-07 15:55:05 +00:00
|
|
|
reply["events"] = events
|
|
|
|
reply["last_week"] = last_week
|
|
|
|
reply["two_weeks_ago"] = two_weeks_ago
|
|
|
|
|
|
|
|
reply["fullcalendar_events"] = calendar.build_events(events)
|
2024-02-18 22:36:15 +00:00
|
|
|
reply["errors"] = errors
|
2023-11-07 15:55:05 +00:00
|
|
|
|
|
|
|
return reply
|