Add Nailsea market days

Closes: #37
This commit is contained in:
Edward Betts 2023-10-29 16:28:13 +00:00
parent f4c914a126
commit 9a79573e16

View file

@ -404,6 +404,37 @@ def tobacco_factory_market_days(start_date: date) -> list[Event]:
return events
def nailsea_farmers_market_days(start_date: date) -> list[Event]:
"""Nailsea Farmers Market days for the next 12 months from a given date."""
events: list[Event] = []
current_date = start_date
count = 0
tz = pytz.timezone("Europe/London")
t = time(9, 0) # The market starts at 9am
while count < 12:
# Calculate the 3rd Saturday of the current month
third_saturday = current_date + relativedelta(day=1, weekday=SA(+3))
# Include it in the list only if it's on or after the start_date
if third_saturday >= start_date:
events.append(
Event(
name="market",
title="Nailsea Farmers Market",
date=tz.localize(datetime.combine(third_saturday, t)),
)
)
count += 1
# Move to the next month
current_date += relativedelta(months=1)
current_date = date(current_date.year, current_date.month, 1)
return events
# Test the function
if __name__ == "__main__":
start_date = date(2023, 10, 29)
@ -583,7 +614,11 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]:
"xmas_last_posting_dates": xmas_last_posting_dates,
"gwr_advance_tickets": find_gwr_advance_ticket_date(),
"critical_mass": critical_mass(today),
"market": windmill_hill_market_days(today) + tobacco_factory_market_days(today),
"market": (
windmill_hill_market_days(today)
+ tobacco_factory_market_days(today)
+ nailsea_farmers_market_days(today)
),
"rockets": thespacedevs.get_launches(rocket_dir, limit=40),
}