From f4c914a126ba5c4823d47215a8587acdbbc89c5d Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 29 Oct 2023 16:15:53 +0000 Subject: [PATCH] Add Tobacco factory market days Closes: #38 --- agenda/__init__.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/agenda/__init__.py b/agenda/__init__.py index 217590d..56fde9e 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -374,6 +374,36 @@ def windmill_hill_market_days(start_date: date) -> list[Event]: return events +def tobacco_factory_market_days(start_date: date) -> list[Event]: + """Tobacco Factory 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(10, 0) + + while count < 52: # 52 weeks in a year + # Calculate the next Sunday from the current date + next_sunday = current_date + relativedelta(weekday=6) # Sunday is 6 + + # Include it in the list only if it's on or after the start_date + if next_sunday >= start_date: + events.append( + Event( + name="market", + title="Tobacco Factory Sunday Market", + date=tz.localize(datetime.combine(next_sunday, t)), + ) + ) + count += 1 + + # Move to the next week + current_date += timedelta(weeks=1) + + return events + + # Test the function if __name__ == "__main__": start_date = date(2023, 10, 29) @@ -553,7 +583,7 @@ 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), + "market": windmill_hill_market_days(today) + tobacco_factory_market_days(today), "rockets": thespacedevs.get_launches(rocket_dir, limit=40), }