Show past 12 months of market days on calendar
This commit is contained in:
parent
e8bda4f969
commit
aeeeea2041
|
@ -420,9 +420,9 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]:
|
|||
"gwr_advance_tickets": gwr.advance_ticket_date(data_dir),
|
||||
"critical_mass": critical_mass(today),
|
||||
"market": (
|
||||
markets.windmill_hill(today)
|
||||
+ markets.tobacco_factory(today)
|
||||
+ markets.nailsea_farmers(today)
|
||||
markets.windmill_hill(last_year)
|
||||
+ markets.tobacco_factory(last_year)
|
||||
+ markets.nailsea_farmers(last_year)
|
||||
),
|
||||
"rockets": thespacedevs.get_launches(rocket_dir, limit=40),
|
||||
}
|
||||
|
|
|
@ -7,9 +7,11 @@ from dateutil.relativedelta import SA, relativedelta
|
|||
|
||||
from .types import Event
|
||||
|
||||
uk_tz = pytz.timezone("Europe/London")
|
||||
|
||||
def windmill_hill(start_date: date) -> list[Event]:
|
||||
"""Windmill Hill Market days for the next 12 months from a given date."""
|
||||
|
||||
def windmill_hill(start_date: date, months: int = 24) -> list[Event]:
|
||||
"""Windmill Hill Market days for the next 24 months from a given date."""
|
||||
events: list[Event] = []
|
||||
current_date = start_date
|
||||
url = (
|
||||
|
@ -20,11 +22,10 @@ def windmill_hill(start_date: date) -> list[Event]:
|
|||
# To keep count of how many market days have been calculated
|
||||
count = 0
|
||||
|
||||
tz = pytz.timezone("Europe/London")
|
||||
start = time(10, 0)
|
||||
end = time(15, 0)
|
||||
|
||||
while count < 12:
|
||||
while count < months:
|
||||
# Skip months outside of April to December
|
||||
if current_date.month < 4 or current_date.month > 12:
|
||||
current_date += relativedelta(months=1)
|
||||
|
@ -40,8 +41,8 @@ def windmill_hill(start_date: date) -> list[Event]:
|
|||
Event(
|
||||
name="market",
|
||||
title="Windmill Hill Market",
|
||||
date=tz.localize(datetime.combine(first_saturday, start)),
|
||||
end_date=tz.localize(datetime.combine(first_saturday, end)),
|
||||
date=uk_tz.localize(datetime.combine(first_saturday, start)),
|
||||
end_date=uk_tz.localize(datetime.combine(first_saturday, end)),
|
||||
url=url,
|
||||
)
|
||||
)
|
||||
|
@ -54,7 +55,7 @@ def windmill_hill(start_date: date) -> list[Event]:
|
|||
return events
|
||||
|
||||
|
||||
def tobacco_factory(start_date: date) -> list[Event]:
|
||||
def tobacco_factory(start_date: date, weeks: int = 52 * 2) -> list[Event]:
|
||||
"""Tobacco Factory Market days for the next 12 months from a given date."""
|
||||
events: list[Event] = []
|
||||
current_date = start_date
|
||||
|
@ -62,11 +63,10 @@ def tobacco_factory(start_date: date) -> list[Event]:
|
|||
|
||||
url = "https://tobaccofactory.com/whats-on/sunday-market/"
|
||||
|
||||
tz = pytz.timezone("Europe/London")
|
||||
start = time(10, 0)
|
||||
end = time(14, 30)
|
||||
|
||||
while count < 52: # 52 weeks in a year
|
||||
while count < weeks: # 52 weeks in a year
|
||||
# Calculate the next Sunday from the current date
|
||||
next_sunday = current_date + relativedelta(weekday=6) # Sunday is 6
|
||||
|
||||
|
@ -76,8 +76,8 @@ def tobacco_factory(start_date: date) -> list[Event]:
|
|||
Event(
|
||||
name="market",
|
||||
title="Tobacco Factory Sunday Market",
|
||||
date=tz.localize(datetime.combine(next_sunday, start)),
|
||||
end_date=tz.localize(datetime.combine(next_sunday, end)),
|
||||
date=uk_tz.localize(datetime.combine(next_sunday, start)),
|
||||
end_date=uk_tz.localize(datetime.combine(next_sunday, end)),
|
||||
url=url,
|
||||
)
|
||||
)
|
||||
|
@ -89,16 +89,15 @@ def tobacco_factory(start_date: date) -> list[Event]:
|
|||
return events
|
||||
|
||||
|
||||
def nailsea_farmers(start_date: date) -> list[Event]:
|
||||
def nailsea_farmers(start_date: date, months: int = 52 * 2) -> 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:
|
||||
while count < months:
|
||||
# Calculate the 3rd Saturday of the current month
|
||||
third_saturday = current_date + relativedelta(day=1, weekday=SA(+3))
|
||||
|
||||
|
@ -108,7 +107,7 @@ def nailsea_farmers(start_date: date) -> list[Event]:
|
|||
Event(
|
||||
name="market",
|
||||
title="Nailsea Farmers Market",
|
||||
date=tz.localize(datetime.combine(third_saturday, t)),
|
||||
date=uk_tz.localize(datetime.combine(third_saturday, t)),
|
||||
)
|
||||
)
|
||||
count += 1
|
||||
|
|
Loading…
Reference in a new issue