Split out rio_carnival_events function
This commit is contained in:
parent
78c90b0164
commit
18d8fa6b7c
33
agenda/carnival.py
Normal file
33
agenda/carnival.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
"""Calcuate the date for carnival."""
|
||||
|
||||
from datetime import date, timedelta
|
||||
|
||||
from dateutil.easter import easter
|
||||
|
||||
from .types import Event
|
||||
|
||||
|
||||
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
|
|
@ -14,12 +14,12 @@ import isodate # type: ignore
|
|||
import lxml
|
||||
import pytz
|
||||
import yaml
|
||||
from dateutil.easter import easter
|
||||
|
||||
from . import (
|
||||
accommodation,
|
||||
birthday,
|
||||
calendar,
|
||||
carnival,
|
||||
conference,
|
||||
domains,
|
||||
economist,
|
||||
|
@ -66,32 +66,6 @@ def midnight(d: date) -> datetime:
|
|||
return datetime.combine(d, datetime.min.time())
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def dates_from_rrule(
|
||||
rrule: str, start: date, end: date
|
||||
) -> typing.Sequence[datetime | date]:
|
||||
|
@ -458,7 +432,7 @@ async def get_data(
|
|||
events += economist.publication_dates(last_week, next_year)
|
||||
events += meetup.get_events(my_data)
|
||||
events += hn.whoishiring(last_year, next_year)
|
||||
events += rio_carnival_events(last_year, next_year)
|
||||
events += carnival.rio_carnival_events(last_year, next_year)
|
||||
|
||||
# hide markets that happen while away
|
||||
optional = [
|
||||
|
|
Loading…
Reference in a new issue