Compare commits
5 commits
c3be926ff7
...
f5a8676336
Author | SHA1 | Date | |
---|---|---|---|
Edward Betts | f5a8676336 | ||
Edward Betts | 2f574264e5 | ||
Edward Betts | 340905ecff | ||
Edward Betts | 010f56aabf | ||
Edward Betts | 7755bcf668 |
|
@ -24,7 +24,7 @@ def format_list_with_ampersand(items: list[str]) -> str:
|
||||||
|
|
||||||
def get_country(alpha_2: str) -> pycountry.db.Country | None:
|
def get_country(alpha_2: str) -> pycountry.db.Country | None:
|
||||||
"""Lookup country by alpha-2 country code."""
|
"""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")
|
return pycountry.db.Country(flag="🇪🇺", name="ESA")
|
||||||
if not alpha_2:
|
if not alpha_2:
|
||||||
return None
|
return None
|
||||||
|
@ -33,9 +33,10 @@ def get_country(alpha_2: str) -> pycountry.db.Country | None:
|
||||||
flag="\U0001F1FD\U0001F1F0", name="Kosovo", alpha_2="xk"
|
flag="\U0001F1FD\U0001F1F0", name="Kosovo", alpha_2="xk"
|
||||||
)
|
)
|
||||||
|
|
||||||
country: pycountry.db.Country
|
country: pycountry.db.Country = None
|
||||||
if len(alpha_2) == 2:
|
if len(alpha_2) == 2:
|
||||||
country = pycountry.countries.get(alpha_2=alpha_2.upper())
|
country = pycountry.countries.get(alpha_2=alpha_2.upper())
|
||||||
elif len(alpha_2) == 3:
|
elif len(alpha_2) == 3:
|
||||||
country = pycountry.countries.get(alpha_3=alpha_2.upper())
|
country = pycountry.countries.get(alpha_3=alpha_2.upper())
|
||||||
|
|
||||||
return country
|
return country
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
import typing
|
import typing
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, timedelta
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
|
||||||
|
@ -43,11 +43,11 @@ def busy_event(e: Event) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def get_busy_events(
|
def get_busy_events(
|
||||||
today: date, config: flask.config.Config, trips: list[Trip]
|
start: date, config: flask.config.Config, trips: list[Trip]
|
||||||
) -> list[Event]:
|
) -> list[Event]:
|
||||||
"""Find busy events from a year ago to two years in the future."""
|
"""Find busy events from a year ago to two years in the future."""
|
||||||
last_year = today - timedelta(days=365)
|
last_year = start - timedelta(days=365)
|
||||||
next_year = today + timedelta(days=2 * 365)
|
next_year = start + timedelta(days=2 * 365)
|
||||||
|
|
||||||
my_data = config["PERSONAL_DATA"]
|
my_data = config["PERSONAL_DATA"]
|
||||||
events = events_yaml.read(my_data, last_year, next_year, skip_trips=True)
|
events = events_yaml.read(my_data, last_year, next_year, skip_trips=True)
|
||||||
|
@ -71,7 +71,7 @@ def get_busy_events(
|
||||||
busy_events = [
|
busy_events = [
|
||||||
e
|
e
|
||||||
for e in sorted(events, key=lambda e: e.as_date)
|
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 e.as_date < next_year
|
||||||
and busy_event(e)
|
and busy_event(e)
|
||||||
]
|
]
|
||||||
|
@ -79,16 +79,15 @@ def get_busy_events(
|
||||||
return 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."""
|
"""Next ten weekends."""
|
||||||
today = datetime.today()
|
weekday = start.weekday()
|
||||||
weekday = today.weekday()
|
|
||||||
|
|
||||||
# Calculate the difference to the next or previous Saturday
|
# Calculate the difference to the next or previous Saturday
|
||||||
if weekday == 6: # Sunday
|
if weekday == 6: # Sunday
|
||||||
start_date = (today - timedelta(days=1)).date()
|
start_date = start - timedelta(days=1)
|
||||||
else:
|
else:
|
||||||
start_date = (today + timedelta(days=(5 - weekday))).date()
|
start_date = start + timedelta(days=(5 - weekday))
|
||||||
|
|
||||||
weekends_info = []
|
weekends_info = []
|
||||||
for i in range(52):
|
for i in range(52):
|
||||||
|
|
|
@ -45,7 +45,7 @@ def build_events(events: list[Event]) -> list[dict[str, typing.Any]]:
|
||||||
|
|
||||||
item = {
|
item = {
|
||||||
"allDay": False,
|
"allDay": False,
|
||||||
"title": "checkin: " + e.title,
|
"title": "check-in: " + e.title,
|
||||||
"start": e.date.isoformat(),
|
"start": e.date.isoformat(),
|
||||||
"url": e.url,
|
"url": e.url,
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ from agenda.types import StrDict, Trip
|
||||||
|
|
||||||
|
|
||||||
def travel_legs(trip: Trip, stats: StrDict) -> None:
|
def travel_legs(trip: Trip, stats: StrDict) -> None:
|
||||||
"""Calcuate stats for travel legs."""
|
"""Calculate stats for travel legs."""
|
||||||
for leg in trip.travel:
|
for leg in trip.travel:
|
||||||
if leg["type"] == "flight":
|
if leg["type"] == "flight":
|
||||||
stats.setdefault("flight_count", 0)
|
stats.setdefault("flight_count", 0)
|
||||||
|
|
|
@ -245,7 +245,7 @@ def get_locations(trip: Trip) -> dict[str, StrDict]:
|
||||||
|
|
||||||
|
|
||||||
def coordinate_dict(item: StrDict, coord_type: str) -> StrDict:
|
def coordinate_dict(item: StrDict, coord_type: str) -> StrDict:
|
||||||
"""Build coodinate dict for item."""
|
"""Build coordinate dict for item."""
|
||||||
return {
|
return {
|
||||||
"name": item["name"],
|
"name": item["name"],
|
||||||
"type": coord_type,
|
"type": coord_type,
|
||||||
|
|
|
@ -171,7 +171,7 @@ class Trip:
|
||||||
@functools.cached_property
|
@functools.cached_property
|
||||||
def show_flags(self) -> bool:
|
def show_flags(self) -> bool:
|
||||||
"""Show flags for international trips."""
|
"""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
|
@property
|
||||||
def countries_str(self) -> str:
|
def countries_str(self) -> str:
|
||||||
|
|
|
@ -284,7 +284,7 @@
|
||||||
| Venue: {{ item.venue }}
|
| Venue: {{ item.venue }}
|
||||||
| Location: {{ item.location }}
|
| Location: {{ item.location }}
|
||||||
{% if country %}
|
{% if country %}
|
||||||
{{ country.flag }}
|
{{ flag(trip, country.flag) }}
|
||||||
{% elif item.online %}
|
{% elif item.online %}
|
||||||
💻 Online
|
💻 Online
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -27,7 +27,12 @@
|
||||||
<div>Conferences in {{ year }}: {{ year_stats.conferences }}</div>
|
<div>Conferences in {{ year }}: {{ year_stats.conferences }}</div>
|
||||||
<div>{{ countries | count }} countries visited in {{ year }}:
|
<div>{{ countries | count }} countries visited in {{ year }}:
|
||||||
{% for c in countries %}
|
{% for c in countries %}
|
||||||
<span class="text-nowrap">{{ c.flag }} {{ c.name }}</span>
|
<span class="text-nowrap border border-2 px-2 my-3 mx-1">
|
||||||
|
{{ c.flag }} {{ c.name }} ({{ c.alpha_2 }})
|
||||||
|
{% if c.alpha_2 not in previously_visited %}
|
||||||
|
<span class="badge text-bg-info">new</span>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -17,15 +17,21 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
{% for weekend in items %}
|
{% for weekend in items %}
|
||||||
<tr>
|
{% set week_number = weekend.date.isocalendar().week %}
|
||||||
<td class="text-end">
|
{% if week_number == current_week_number %}
|
||||||
{{ weekend.date.isocalendar().week }}
|
{% set extra_class = " bg-warning-subtle" %}
|
||||||
|
{% else %}
|
||||||
|
{% set extra_class = "" %}
|
||||||
|
{% endif %}
|
||||||
|
<tr{% if week_number == current_week_number %} class="bg-warning-subtle"{% endif %}>
|
||||||
|
<td class="text-end{{ extra_class }}">
|
||||||
|
{{ week_number }}
|
||||||
</td>
|
</td>
|
||||||
<td class="text-end text-nowrap">
|
<td class="text-end text-nowrap{{ extra_class }}">
|
||||||
{{ weekend.date.strftime("%-d %b %Y") }}
|
{{ weekend.date.strftime("%-d %b %Y") }}
|
||||||
</td>
|
</td>
|
||||||
{% for day in "saturday", "sunday" %}
|
{% for day in "saturday", "sunday" %}
|
||||||
<td>
|
{% if extra_class %}<td class="{{ extra_class|trim }}">{% else %}<td>{% endif %}
|
||||||
{% if weekend[day] %}
|
{% if weekend[day] %}
|
||||||
{% for event in weekend[day] %}
|
{% for event in weekend[day] %}
|
||||||
<a href="{{ event.url }}">{{ event.title }}</a>{% if not loop.last %},{%endif %}
|
<a href="{{ event.url }}">{{ event.title }}</a>{% if not loop.last %},{%endif %}
|
||||||
|
|
15
web_view.py
15
web_view.py
|
@ -224,11 +224,17 @@ async def gaps_page() -> str:
|
||||||
@app.route("/weekends")
|
@app.route("/weekends")
|
||||||
async def weekends() -> str:
|
async def weekends() -> str:
|
||||||
"""List of available gaps."""
|
"""List of available gaps."""
|
||||||
now = datetime.now()
|
today = date.today()
|
||||||
|
|
||||||
|
current_week_number = today.isocalendar().week
|
||||||
|
|
||||||
|
start = date(today.year, 1, 1)
|
||||||
trip_list = agenda.trip.build_trip_list()
|
trip_list = agenda.trip.build_trip_list()
|
||||||
busy_events = agenda.busy.get_busy_events(now.date(), app.config, trip_list)
|
busy_events = agenda.busy.get_busy_events(start, app.config, trip_list)
|
||||||
weekends = agenda.busy.weekends(busy_events)
|
weekends = agenda.busy.weekends(start, busy_events)
|
||||||
return flask.render_template("weekends.html", today=now.date(), items=weekends)
|
return flask.render_template(
|
||||||
|
"weekends.html", items=weekends, current_week_number=current_week_number
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/travel")
|
@app.route("/travel")
|
||||||
|
@ -580,6 +586,7 @@ def trip_stats() -> str:
|
||||||
distances_by_transport_type=sum_distances_by_transport_type(trip_list),
|
distances_by_transport_type=sum_distances_by_transport_type(trip_list),
|
||||||
yearly_stats=yearly_stats,
|
yearly_stats=yearly_stats,
|
||||||
conferences=conferences,
|
conferences=conferences,
|
||||||
|
previously_visited=app.config.get("PREVIOUSLY_VISITED", set),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue