country_dict = {"label": "number of records", "data": country_numbers, "backgroundColor": random_colour} | country_dict = {"label": "number of records", "data": country_numbers, "backgroundColor": random_colour} | ||||
else: | else: | ||||
country = pycountry.countries.get(alpha_2=country_data[i]) | country = pycountry.countries.get(alpha_2=country_data[i]) | ||||
if country is None: | |||||
if country is not None: | |||||
country_labels.append(country.name) | |||||
country_data[i] = country | |||||
else: | |||||
country = pycountry.historic_countries.get(alpha_2=country_data[i]) | country = pycountry.historic_countries.get(alpha_2=country_data[i]) | ||||
country_labels.append(country.name) | |||||
country_data[i] = country | |||||
if country is not None: | |||||
country_data[i] = country | |||||
country_labels.append(country.name) | |||||
else: | |||||
country_labels.append(country_data[i]) | |||||
country_dataset.append(country_dict) | country_dataset.append(country_dict) | ||||
germany = pycountry.countries.get(alpha_2='DE') | |||||
return render_template('data.html', total_number=total_number, year_data=year_data, year_labels=year_labels, year_dataset=year_dataset, country_data=country_data, country_labels=country_labels, country_dataset=country_dataset, germany=germany) | |||||
return render_template('data.html', total_number=total_number, year_data=year_data, year_labels=year_labels, year_dataset=year_dataset, country_data=country_data, country_labels=country_labels, country_dataset=country_dataset) |
# search for the country in the content element and display it | # search for the country in the content element and display it | ||||
country_code = re.search('FT=D[^\s]*\s(\w{2})', input) | country_code = re.search('FT=D[^\s]*\s(\w{2})', input) | ||||
country = pycountry.countries.get(alpha_2=country_code.group(1)) | country = pycountry.countries.get(alpha_2=country_code.group(1)) | ||||
if country is None: | |||||
country = pycountry.historic_countries.get(alpha_2=country_code.group(1)) | |||||
if country is not None: | if country is not None: | ||||
output['country'] = country | output['country'] = country | ||||
else: | |||||
country = pycountry.historic_countries.get(alpha_2=country_code.group(1)) | |||||
if country is not None: | |||||
output['country'] = country | |||||
else: | |||||
output['country'] = country_code.group(1) | |||||
return output | return output | ||||
{% if i % 2 %} | {% if i % 2 %} | ||||
{{ country_data[i] }}<br> | {{ country_data[i] }}<br> | ||||
{% else %} | {% else %} | ||||
{{ country_data[i].name }} {{ country_data[i].flag }}: | |||||
{% if country_data[i].name is defined %} | |||||
{{ country_data[i].name }} {{ country_data[i].flag }}: | |||||
{% else %} | |||||
{{ country_data[i] }}: | |||||
{% endif %} | |||||
{% endif %} | {% endif %} | ||||
{% endfor %} | {% endfor %} | ||||
</div> | </div> |
{% if result['country'] is defined %} | {% if result['country'] is defined %} | ||||
<p class="mb-2"> | <p class="mb-2"> | ||||
Country: | Country: | ||||
{{ result['country'].name }} | |||||
{{ result['country'].flag }} | |||||
{% if result['country'].name is defined %} | |||||
{{ result['country'].name }} {{ result['country'].flag }} | |||||
{% else %} | |||||
{{ result['country'] }} | |||||
{% endif %} | |||||
</p> | </p> | ||||
{% endif %} | {% endif %} | ||||
{% if result['country'] is defined %} | {% if result['country'] is defined %} | ||||
<p class="mb-2"> | <p class="mb-2"> | ||||
<span class="emphasis">Country:</span> | <span class="emphasis">Country:</span> | ||||
{{ result['country'].name }} | |||||
{{ result['country'].flag }} | |||||
{% if result['country'].name is defined %} | |||||
{{ result['country'].name }} {{ result['country'].flag }} | |||||
{% else %} | |||||
{{ result['country'] }} | |||||
{% endif %} | |||||
</p> | </p> | ||||
{% endif %} | {% endif %} | ||||