I am using pywikibot api to fetch Wikipedia Infobox attributes. Few things I want to extract is population denisty, population, elevation etc. For some of the cities e.g(https://en.wikipedia.org/wiki/Beijing), the api is returning "auto" as value for keys like population_density_km2. For few other cities , I am getting the actual density instead of auto. Anyone has any idea on the reasoning behind this and how can I get the actual value?
import pywikibot
def get_page(city: dict) :
"""
Returns parsed wikipedia page
"""
page = pywikibot.Page(en_wiki, re.search(r'wiki/(.*)', city['article']['value']).group(1))
if page.pageid == 0:
raise Exception('page do not exist')
return page
def get_info_box_details(templates: dict):
"""
Get info box details
"""
infobox_template = []
for tmpl, params in templates:
if 'Infobox' in tmpl:
infobox_template.append(params)
population = { k:v for my_dict in infobox_template for k,v in my_dict.items() if 'population' in k}
print(population)
wiki_page = get_page(city)
templates = wiki_page.raw_extracted_templates
info_box = get_info_box_details(templates)