parent
							
								
									bd3649a6c7
								
							
						
					
					
						commit
						71e9ce4af8
					
				| 
						 | 
					@ -2,27 +2,36 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from datetime import date, time, timedelta
 | 
					from datetime import date, time, timedelta
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from dateutil.relativedelta import TH, relativedelta
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from . import uk_time
 | 
					from . import uk_time
 | 
				
			||||||
from .types import Event
 | 
					from .types import Event
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def publication_dates(start_date: date, end_date: date) -> list[Event]:
 | 
					def publication_dates(start_date: date, end_date: date) -> list[Event]:
 | 
				
			||||||
    """List of Economist publication dates."""
 | 
					    """List of Economist publication dates."""
 | 
				
			||||||
    # Define the publication day (Thursday) and non-publication weeks
 | 
					 | 
				
			||||||
    publication_day = 3  # Thursday (0 - Monday, 1 - Tuesday, ..., 6 - Sunday)
 | 
					 | 
				
			||||||
    # Define the list of weeks when The Economist is not published
 | 
					    # Define the list of weeks when The Economist is not published
 | 
				
			||||||
    non_publication_weeks = [26, 52]
 | 
					    non_publication_weeks = [26, 52]
 | 
				
			||||||
 | 
					    double_issue = {
 | 
				
			||||||
 | 
					        25: "Summer",
 | 
				
			||||||
 | 
					        51: "Christmas",
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    current_date = start_date
 | 
					 | 
				
			||||||
    publication_dates = []
 | 
					 | 
				
			||||||
    t = time(19, 0)
 | 
					    t = time(19, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while current_date <= end_date:
 | 
					    start_thursday = start_date + relativedelta(weekday=TH(+1))
 | 
				
			||||||
        if (
 | 
					    end_thursday = end_date + relativedelta(weekday=TH(+1))
 | 
				
			||||||
            current_date.weekday() == publication_day
 | 
					    days = (end_thursday - start_thursday).days
 | 
				
			||||||
            and current_date.isocalendar().week not in non_publication_weeks
 | 
					 | 
				
			||||||
        ):
 | 
					 | 
				
			||||||
            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]
 | 
					    events: list[Event] = []
 | 
				
			||||||
 | 
					    for offset in range(0, days, 7):
 | 
				
			||||||
 | 
					        pub_date = start_thursday + timedelta(days=offset)
 | 
				
			||||||
 | 
					        week = pub_date.isocalendar().week
 | 
				
			||||||
 | 
					        if week in non_publication_weeks:
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					        e = Event(name="economist", date=uk_time(pub_date, t))
 | 
				
			||||||
 | 
					        if week in double_issue:
 | 
				
			||||||
 | 
					            e.title = double_issue[week] + " double issue"
 | 
				
			||||||
 | 
					        events.append(e)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return events
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue