Geography: Set a better user-agent to access Wikidata

This commit is contained in:
Valentin Lorentz 2021-11-08 23:41:26 +01:00
parent 27c513135c
commit 0a6f598295

View File

@ -110,7 +110,12 @@ LIMIT 1
def _query_sparql(query): def _query_sparql(query):
params = {"format": "json", "query": query} params = {"format": "json", "query": query}
url = SPARQL_URL + "?" + urllib.parse.urlencode(params) url = SPARQL_URL + "?" + urllib.parse.urlencode(params)
content = utils.web.getUrlContent(url)
# Comply with https://meta.wikimedia.org/wiki/User-Agent_policy
headers = utils.web.defaultHeaders.copy()
headers["User-agent"] += " https://github.com/progval/Limnoria/ - Geography plugin"
content = utils.web.getUrlContent(url, headers=headers)
return json.loads(content) return json.loads(content)
def timezone_from_qid(location_qid): def timezone_from_qid(location_qid):