diff --git a/agenda/__init__.py b/agenda/__init__.py index 43c2283..70701fe 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -24,7 +24,7 @@ def format_list_with_ampersand(items: list[str]) -> str: def get_country(alpha_2: str) -> pycountry.db.Country | None: """Lookup country by alpha-2 country code.""" - if alpha_2.count(",") > 10: # ESA + if alpha_2.count(",") > 3: # ESA return pycountry.db.Country(flag="🇪🇺", name="ESA") if not alpha_2: return None @@ -33,9 +33,10 @@ def get_country(alpha_2: str) -> pycountry.db.Country | None: flag="\U0001F1FD\U0001F1F0", name="Kosovo", alpha_2="xk" ) - country: pycountry.db.Country + country: pycountry.db.Country = None if len(alpha_2) == 2: country = pycountry.countries.get(alpha_2=alpha_2.upper()) elif len(alpha_2) == 3: country = pycountry.countries.get(alpha_3=alpha_2.upper()) + return country diff --git a/agenda/busy.py b/agenda/busy.py index d6978d4..81d43ea 100644 --- a/agenda/busy.py +++ b/agenda/busy.py @@ -2,7 +2,7 @@ import itertools import typing -from datetime import date, datetime, timedelta +from datetime import date, timedelta import flask @@ -43,11 +43,11 @@ def busy_event(e: Event) -> bool: def get_busy_events( - today: date, config: flask.config.Config, trips: list[Trip] + start: date, config: flask.config.Config, trips: list[Trip] ) -> list[Event]: """Find busy events from a year ago to two years in the future.""" - last_year = today - timedelta(days=365) - next_year = today + timedelta(days=2 * 365) + last_year = start - timedelta(days=365) + next_year = start + timedelta(days=2 * 365) my_data = config["PERSONAL_DATA"] events = events_yaml.read(my_data, last_year, next_year, skip_trips=True) @@ -71,7 +71,7 @@ def get_busy_events( busy_events = [ e for e in sorted(events, key=lambda e: e.as_date) - if (e.as_date >= today or (e.end_date and e.end_as_date >= today)) + if (e.as_date >= start or (e.end_date and e.end_as_date >= start)) and e.as_date < next_year and busy_event(e) ] @@ -79,16 +79,15 @@ def get_busy_events( return busy_events -def weekends(busy_events: list[Event]) -> typing.Sequence[StrDict]: +def weekends(start: date, busy_events: list[Event]) -> typing.Sequence[StrDict]: """Next ten weekends.""" - today = datetime.today() - weekday = today.weekday() + weekday = start.weekday() # Calculate the difference to the next or previous Saturday if weekday == 6: # Sunday - start_date = (today - timedelta(days=1)).date() + start_date = start - timedelta(days=1) else: - start_date = (today + timedelta(days=(5 - weekday))).date() + start_date = start + timedelta(days=(5 - weekday)) weekends_info = [] for i in range(52): diff --git a/agenda/calendar.py b/agenda/calendar.py index d1fb985..bc00d75 100644 --- a/agenda/calendar.py +++ b/agenda/calendar.py @@ -45,7 +45,7 @@ def build_events(events: list[Event]) -> list[dict[str, typing.Any]]: item = { "allDay": False, - "title": "checkin: " + e.title, + "title": "check-in: " + e.title, "start": e.date.isoformat(), "url": e.url, } diff --git a/agenda/stats.py b/agenda/stats.py index 62b67c2..d9bdc51 100644 --- a/agenda/stats.py +++ b/agenda/stats.py @@ -7,7 +7,7 @@ from agenda.types import StrDict, Trip def travel_legs(trip: Trip, stats: StrDict) -> None: - """Calcuate stats for travel legs.""" + """Calculate stats for travel legs.""" for leg in trip.travel: if leg["type"] == "flight": stats.setdefault("flight_count", 0) diff --git a/agenda/trip.py b/agenda/trip.py index 8cab498..946c3ac 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -245,7 +245,7 @@ def get_locations(trip: Trip) -> dict[str, StrDict]: def coordinate_dict(item: StrDict, coord_type: str) -> StrDict: - """Build coodinate dict for item.""" + """Build coordinate dict for item.""" return { "name": item["name"], "type": coord_type, diff --git a/agenda/types.py b/agenda/types.py index c7bcb45..0bfef4d 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -171,7 +171,7 @@ class Trip: @functools.cached_property def show_flags(self) -> bool: """Show flags for international trips.""" - return len(self.countries) != 1 or self.countries[0].name != "United Kingdom" + return len({c for c in self.countries if c.name != "United Kingdom"}) > 1 @property def countries_str(self) -> str: diff --git a/templates/macros.html b/templates/macros.html index f9ca49f..20cf147 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -284,7 +284,7 @@ | Venue: {{ item.venue }} | Location: {{ item.location }} {% if country %} - {{ country.flag }} + {{ flag(trip, country.flag) }} {% elif item.online %} 💻 Online {% else %} diff --git a/templates/trip/stats.html b/templates/trip/stats.html index 7d81a3d..8644aff 100644 --- a/templates/trip/stats.html +++ b/templates/trip/stats.html @@ -27,7 +27,12 @@