agenda/agenda/economist.py
2023-11-25 09:52:11 +00:00

38 lines
1.1 KiB
Python

"""Next publication date of the Economist."""
from datetime import date, time, timedelta
from dateutil.relativedelta import TH, relativedelta
from . import uk_time
from .types import Event
def publication_dates(start_date: date, end_date: date) -> list[Event]:
"""List of Economist publication dates."""
# Define the list of weeks when The Economist is not published
non_publication_weeks = [26, 52]
double_issue = {
25: "Summer",
51: "Christmas",
}
t = time(19, 0)
start_thursday = start_date + relativedelta(weekday=TH(+1))
end_thursday = end_date + relativedelta(weekday=TH(+1))
days = (end_thursday - start_thursday).days
events: list[Event] = []
for offset in range(0, days, 7):
pub_date = start_thursday + timedelta(days=offset)
week = pub_date.isocalendar().week
if week in non_publication_weeks:
continue
e = Event(name="economist", date=uk_time(pub_date, t))
if week in double_issue:
e.title = double_issue[week] + " double issue"
events.append(e)
return events