From 2c9b97f0c20d40bdcd0da2f1fc43ce7df5fe8af1 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 5 Nov 2023 13:36:42 +0000 Subject: [PATCH] Split conference code into own file --- agenda/__init__.py | 27 ++------------------------- agenda/conference.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 agenda/conference.py diff --git a/agenda/__init__.py b/agenda/__init__.py index 2dccc2e..05d9ee0 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -6,7 +6,6 @@ import typing import warnings from datetime import date, datetime, time, timedelta, timezone from time import time as unixtime -from typing import List import dateutil import dateutil.parser @@ -26,6 +25,7 @@ from agenda import thespacedevs from . import ( birthday, calendar, + conference, economist, fx, gwr, @@ -251,29 +251,6 @@ def as_date(d: date | datetime) -> date: 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]: """Get birthdays from config.""" 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 += get_accommodation(today, os.path.join(my_data, "accommodation.yaml")) 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) next_up_series = Event( diff --git a/agenda/conference.py b/agenda/conference.py new file mode 100644 index 0000000..f29e05e --- /dev/null +++ b/agenda/conference.py @@ -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