Parcourir la source

refined country parsing code

solr_update
Simon Bowie il y a 2 ans
Parent
révision
49f07f5087
5 fichiers modifiés avec 31 ajouts et 13 suppressions
  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 Voir le fichier

@@ -45,12 +45,16 @@ def main_data():
country_dict = {"label": "number of records", "data": country_numbers, "backgroundColor": random_colour}
else:
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_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)

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 Voir le fichier

@@ -98,10 +98,14 @@ def parse_result(id, input):
# search for the country in the content element and display it
country_code = re.search('FT=D[^\s]*\s(\w{2})', input)
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:
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


+ 5
- 1
web/app/templates/data.html Voir le fichier

@@ -23,7 +23,11 @@ There are a total of {{ total_number }} patents.
{% if i % 2 %}
{{ country_data[i] }}<br>
{% 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 %}
{% endfor %}
</div>

+ 5
- 2
web/app/templates/record.html Voir le fichier

@@ -28,8 +28,11 @@
{% if result['country'] is defined %}
<p class="mb-2">
Country:
{{ result['country'].name }}
{{ result['country'].flag }}
{% if result['country'].name is defined %}
{{ result['country'].name }} {{ result['country'].flag }}
{% else %}
{{ result['country'] }}
{% endif %}
</p>
{% endif %}


+ 5
- 2
web/app/templates/search.html Voir le fichier

@@ -54,8 +54,11 @@
{% if result['country'] is defined %}
<p class="mb-2">
<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>
{% endif %}


Chargement…
Annuler
Enregistrer