Split conference code into own file

This commit is contained in:
Edward Betts 2023-11-05 13:36:42 +00:00
parent 7104f8eac3
commit 2c9b97f0c2
2 changed files with 30 additions and 25 deletions

View file

@ -6,7 +6,6 @@ import typing
import warnings import warnings
from datetime import date, datetime, time, timedelta, timezone from datetime import date, datetime, time, timedelta, timezone
from time import time as unixtime from time import time as unixtime
from typing import List
import dateutil import dateutil
import dateutil.parser import dateutil.parser
@ -26,6 +25,7 @@ from agenda import thespacedevs
from . import ( from . import (
birthday, birthday,
calendar, calendar,
conference,
economist, economist,
fx, fx,
gwr, gwr,
@ -251,29 +251,6 @@ def as_date(d: date | datetime) -> date:
return d.date() if isinstance(d, datetime) else d return d.date() if isinstance(d, datetime) else d
def get_conferences(filepath: str) -> List[Event]:
"""Read conferences from a YAML file and return a list of Event objects."""
with open(filepath, "r") as f:
data = yaml.safe_load(f)
events = []
for conf in data.get("conferences", []):
start_date = conf["start"]
end_date = conf["end"]
# Skip the conference if it is before the input date.
event = Event(
name="conference",
date=start_date,
end_date=end_date,
title=f'{conf["name"]} ({conf["location"]})',
url=conf.get("url"),
)
events.append(event)
return events
def get_accommodation(from_date: date, filepath: str) -> list[Event]: def get_accommodation(from_date: date, filepath: str) -> list[Event]:
"""Get birthdays from config.""" """Get birthdays from config."""
events = [] events = []
@ -371,7 +348,7 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]:
events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml")) events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml"))
events += get_accommodation(today, os.path.join(my_data, "accommodation.yaml")) events += get_accommodation(today, os.path.join(my_data, "accommodation.yaml"))
events += travel.all_events(today, config["data"]["personal-data"]) events += travel.all_events(today, config["data"]["personal-data"])
events += get_conferences(os.path.join(my_data, "conferences.yaml")) events += conference.get_list(os.path.join(my_data, "conferences.yaml"))
events += waste_collection_events() + bristol_waste_collection_events(today) events += waste_collection_events() + bristol_waste_collection_events(today)
next_up_series = Event( next_up_series = Event(

28
agenda/conference.py Normal file
View file

@ -0,0 +1,28 @@
"""Conferences."""
import yaml
from .types import Event
def get_list(filepath: str) -> list[Event]:
"""Read conferences from a YAML file and return a list of Event objects."""
with open(filepath, "r") as f:
data = yaml.safe_load(f)
events = []
for conf in data.get("conferences", []):
start_date = conf["start"]
end_date = conf["end"]
# Skip the conference if it is before the input date.
event = Event(
name="conference",
date=start_date,
end_date=end_date,
title=f'{conf["name"]} ({conf["location"]})',
url=conf.get("url"),
)
events.append(event)
return events