parent
a9539545fa
commit
c6bc2f5f72
|
@ -5,7 +5,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import typing
|
import typing
|
||||||
import warnings
|
import warnings
|
||||||
from datetime import date, datetime, timedelta, timezone
|
from datetime import date, datetime, time, timedelta, timezone
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from time import time as unixtime
|
from time import time as unixtime
|
||||||
from typing import List
|
from typing import List
|
||||||
|
@ -21,7 +21,7 @@ import pytz
|
||||||
import requests
|
import requests
|
||||||
import yaml
|
import yaml
|
||||||
from dateutil.easter import easter
|
from dateutil.easter import easter
|
||||||
from dateutil.relativedelta import FR, relativedelta
|
from dateutil.relativedelta import FR, SA, relativedelta
|
||||||
|
|
||||||
from agenda import thespacedevs
|
from agenda import thespacedevs
|
||||||
|
|
||||||
|
@ -327,6 +327,50 @@ def critical_mass(start_date: date, limit: int = 12) -> list[Event]:
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
|
||||||
|
def windmill_hill_market_days(start_date: date) -> list[Event]:
|
||||||
|
"""Windmill Hill Market days for the next 12 months from a given date."""
|
||||||
|
events: list[Event] = []
|
||||||
|
current_date = start_date
|
||||||
|
|
||||||
|
# To keep count of how many market days have been calculated
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
tz = pytz.timezone("Europe/London")
|
||||||
|
|
||||||
|
while count < 12:
|
||||||
|
# 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(
|
||||||
|
name="market",
|
||||||
|
title="Windmill Hill Market",
|
||||||
|
date=tz.localize(datetime.combine(first_saturday, time(10, 0))),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
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)
|
||||||
|
print(windmill_hill_market_days(start_date))
|
||||||
|
|
||||||
|
|
||||||
def as_date(d: date | datetime) -> date:
|
def as_date(d: date | datetime) -> date:
|
||||||
"""Return date for given date or datetime."""
|
"""Return date for given date or datetime."""
|
||||||
return d.date() if isinstance(d, datetime) else d
|
return d.date() if isinstance(d, datetime) else d
|
||||||
|
@ -500,6 +544,7 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]:
|
||||||
"xmas_last_posting_dates": xmas_last_posting_dates,
|
"xmas_last_posting_dates": xmas_last_posting_dates,
|
||||||
"gwr_advance_tickets": find_gwr_advance_ticket_date(),
|
"gwr_advance_tickets": find_gwr_advance_ticket_date(),
|
||||||
"critical_mass": critical_mass(today),
|
"critical_mass": critical_mass(today),
|
||||||
|
"market": windmill_hill_market_days(today),
|
||||||
"rockets": thespacedevs.get_launches(rocket_dir, limit=40),
|
"rockets": thespacedevs.get_launches(rocket_dir, limit=40),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue