Compare commits
2 commits
6a82e3d8f4
...
bcdc8e69b4
Author | SHA1 | Date | |
---|---|---|---|
Edward Betts | bcdc8e69b4 | ||
Edward Betts | 495f0b9744 |
|
@ -10,6 +10,7 @@ from datetime import date, datetime, timedelta
|
|||
import dateutil.rrule
|
||||
import dateutil.tz
|
||||
import holidays # type: ignore
|
||||
import isodate
|
||||
import lxml
|
||||
import pytz
|
||||
import yaml
|
||||
|
@ -22,7 +23,6 @@ from . import (
|
|||
economist,
|
||||
fx,
|
||||
gwr,
|
||||
markets,
|
||||
stock_market,
|
||||
subscription,
|
||||
sun,
|
||||
|
@ -144,10 +144,22 @@ def get_yaml_event_date_field(item: dict[str, str]) -> str:
|
|||
)
|
||||
|
||||
|
||||
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")
|
||||
)
|
||||
|
||||
|
||||
def read_events_yaml(data_dir: str, start: date, end: date) -> list[Event]:
|
||||
"""Read eventes from YAML file."""
|
||||
events: list[Event] = []
|
||||
for item in yaml.safe_load(open(os.path.join(data_dir, "events.yaml"))):
|
||||
duration = (
|
||||
isodate.parse_duration(item["duration"]) if "duration" in item else None
|
||||
)
|
||||
dates = (
|
||||
dates_from_rrule(item["rrule"], start, end)
|
||||
if "rrule" in item
|
||||
|
@ -158,7 +170,13 @@ def read_events_yaml(data_dir: str, start: date, end: date) -> list[Event]:
|
|||
name=item["name"],
|
||||
date=dt,
|
||||
end_date=(
|
||||
item.get("end_date") if item["name"] != "travel_insurance" else None
|
||||
dt + duration
|
||||
if duration
|
||||
else (
|
||||
item.get("end_date")
|
||||
if item["name"] != "travel_insurance"
|
||||
else None
|
||||
)
|
||||
),
|
||||
title=item.get("title"),
|
||||
url=item.get("url"),
|
||||
|
@ -217,13 +235,7 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]:
|
|||
minus_365, plus_365, "us_clock_change", "America/New_York"
|
||||
),
|
||||
"mothers_day": uk_holiday.get_mothers_day(today),
|
||||
# "fathers_day": uk_holiday.get_fathers_day(today),
|
||||
"gwr_advance_tickets": gwr_advance_tickets,
|
||||
"market": (
|
||||
markets.windmill_hill(last_year, next_year)
|
||||
+ markets.tobacco_factory(last_year, next_year)
|
||||
+ markets.nailsea_farmers(last_year, next_year)
|
||||
),
|
||||
"rockets": rockets,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue