From 9a79573e16aebd9b3900e8e9bfaf638142165b56 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 29 Oct 2023 16:28:13 +0000 Subject: [PATCH] Add Nailsea market days Closes: #37 --- agenda/__init__.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/agenda/__init__.py b/agenda/__init__.py index 56fde9e..d6ec273 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -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), }