Selaa lähdekoodia

refined country parsing code

solr_update
Simon Bowie 2 vuotta sitten
vanhempi
commit
49f07f5087
5 muutettua tiedostoa jossa 31 lisäystä ja 13 poistoa
  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 Näytä tiedosto

@@ -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 Näytä tiedosto

@@ -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 Näytä tiedosto

@@ -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 Näytä tiedosto

@@ -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 Näytä tiedosto

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


Loading…
Peruuta
Tallenna