diff --git a/templates/accommodation.html b/templates/accommodation.html index ee98ef4..a7f9b21 100644 --- a/templates/accommodation.html +++ b/templates/accommodation.html @@ -1,9 +1,10 @@ {% extends "base.html" %} {% block style %} +{% set column_count = 7 %} {% endblock %} {% macro row(item, badge) %} +{% set country = get_country(item.country) %}
{{ item.from.strftime("%a, %d %b %Y") }}
{{ item.to.strftime("%a, %d %b") }}
{{ (item.to.date() - item.from.date()).days }}
{{ item.name }}
{{ item.operator }}
{{ item.location }}
+
+ {% if country %} + {{ country.flag }} {{ country.name }} + {% else %} + + country code {{ item.country }} not found + + {% endif %} +
{% endmacro %} {% macro section(heading, item_list, badge) %} diff --git a/web_view.py b/web_view.py index 0a31d2e..041d9c2 100755 --- a/web_view.py +++ b/web_view.py @@ -7,9 +7,11 @@ import operator import os.path import sys import traceback +import typing from datetime import date, datetime import flask +import pycountry import werkzeug import werkzeug.debug.tbtools import yaml @@ -140,11 +142,15 @@ def accommodation_list() -> str: if stay["country"] != "gb" ) + def get_country(alpha_2: str) -> str | None: + return typing.cast(str | None, pycountry.countries.get(alpha_2=alpha_2.upper())) + return flask.render_template( "accommodation.html", items=items, total_nights_2024=total_nights_2024, nights_abroad_2024=nights_abroad_2024, + get_country=get_country, )