Reorganise code
This commit is contained in:
parent
943d45bd27
commit
ac456ce5be
6 changed files with 302 additions and 308 deletions
|
|
@ -1,18 +1,10 @@
|
|||
"""Next publication date of the Economist."""
|
||||
|
||||
from datetime import date, datetime, time, timedelta
|
||||
|
||||
import pytz
|
||||
from datetime import date, time, timedelta
|
||||
|
||||
from . import uk_time
|
||||
from .types import Event
|
||||
|
||||
uk_tz = pytz.timezone("Europe/London")
|
||||
|
||||
|
||||
def add_pub_time(pub_date: date) -> datetime:
|
||||
"""Publication time is 19:00."""
|
||||
return uk_tz.localize(datetime.combine(pub_date, time(19, 0)))
|
||||
|
||||
|
||||
def publication_dates(start_date: date, end_date: date) -> list[Event]:
|
||||
"""List of Economist publication dates."""
|
||||
|
|
@ -23,13 +15,14 @@ def publication_dates(start_date: date, end_date: date) -> list[Event]:
|
|||
|
||||
current_date = start_date
|
||||
publication_dates = []
|
||||
t = time(19, 0)
|
||||
|
||||
while current_date <= end_date:
|
||||
if (
|
||||
current_date.weekday() == publication_day
|
||||
and current_date.isocalendar().week not in non_publication_weeks
|
||||
):
|
||||
publication_dates.append(add_pub_time(current_date))
|
||||
publication_dates.append(uk_time(current_date, t))
|
||||
current_date += timedelta(days=1)
|
||||
|
||||
return [Event(name="economist", date=pub_date) for pub_date in publication_dates]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue