Browse Source

refined country parsing code

solr_update
Simon Bowie 2 years ago
parent
commit
49f07f5087
5 changed files with 31 additions and 13 deletions
  1. +10
    -6
      web/app/data.py
  2. +6
    -2
      web/app/solr.py
  3. +5
    -1
      web/app/templates/data.html
  4. +5
    -2
      web/app/templates/record.html
  5. +5
    -2
      web/app/templates/search.html

+ 10
- 6
web/app/data.py View File

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)

+ 6
- 2
web/app/solr.py View File

# 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



+ 5
- 1
web/app/templates/data.html View File

{% 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>

+ 5
- 2
web/app/templates/record.html View File

{% 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 %}



+ 5
- 2
web/app/templates/search.html View File

{% 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 %}



Loading…
Cancel
Save