Merge branch 'main' of git.4angle.com:edward/agenda

This commit is contained in:
Edward Betts 2023-11-12 20:00:03 +01:00
commit 77d2fef43a

View file

@ -1,102 +0,0 @@
"""Market days."""
from datetime import date, time, timedelta
import pytz
from dateutil.relativedelta import SA, relativedelta
from . import uk_time
from .types import Event
uk_tz = pytz.timezone("Europe/London")
def event(title: str, d: date, start: time, end: time, url: str) -> Event:
"""Build Event object for market."""
return Event(
name="market",
title=title,
date=uk_time(d, start),
end_date=uk_time(d, end),
url=url,
)
def windmill_hill(start_date: date, end_date: date) -> list[Event]:
"""Windmill Hill Market days betwen start and end dates."""
events: list[Event] = []
current_date = start_date
url = (
"https://www.windmillhillcityfarm.org.uk"
+ "/visit-us/shops-more/windmill-hill-market-bristol-market/"
)
start, end = time(10, 0), time(15, 0)
while current_date < end_date:
# Skip months outside of April to December
if current_date.month < 4 or current_date.month > 12:
current_date += relativedelta(months=1)
current_date = date(current_date.year, current_date.month, 1)
continue
# Calculate the first Saturday of the current month
first_saturday = current_date + relativedelta(day=1, weekday=SA(+1))
# Include it in the list only if it's on or after the start_date
if first_saturday >= start_date:
events.append(
event("Windmill Hill Market", first_saturday, start, end, url)
)
# Move to the next month
current_date += relativedelta(months=1)
current_date = date(current_date.year, current_date.month, 1)
return events
def tobacco_factory(start_date: date, end_date: date) -> list[Event]:
"""Tobacco Factory Market days for the next 12 months from a given date."""
events: list[Event] = []
current_date = start_date
url = "https://tobaccofactory.com/whats-on/sunday-market/"
start, end = time(10, 0), time(14, 30)
while current_date <= end_date:
# 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("Tobacco Factory Sunday Market", next_sunday, start, end, url)
)
# Move to the next week
current_date += timedelta(weeks=1)
return events
def nailsea_farmers(start_date: date, end_date: date) -> list[Event]:
"""Nailsea Farmers Market days between start and end dates."""
events: list[Event] = []
current_date = start_date
start, end = time(9, 0), time(13, 0) # Times: 9am-1pm
url = "https://www.somersetfarmersmarkets.co.uk/markets/nailsea/"
while current_date < end_date:
# 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("Nailsea Farmers Market", third_saturday, start, end, url)
)
# Move to the next month
current_date += relativedelta(months=1)
current_date = date(current_date.year, current_date.month, 1)
return events