Skip to content

Commit 84f5f40

Browse files
committed
Fixed sdow api wikipedia url changes
1 parent 77d6eeb commit 84f5f40

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

sdow/helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"""
44

55
import requests
6+
import os
67

7-
8-
WIKIPEDIA_API_URL = 'https://en.wikipedia.org/w/api.php'
9-
8+
WIKIPEDIA_API_URL = os.environ.get('WIKIPEDIA_API_URL','https://en.wikipedia.org/w/api.php')
9+
WIKIPEDIA_USER_AGENT = os.environ.get('WIKIPEDIA_USER_AGENT','Six Degrees of Wikipedia/1.0 (https://www.sixdegreesofwikipedia.com/; [email protected])')
10+
WIKIPEDIA_BROKEN_URL_TEMPLATE = os.environ.get('WIKIPEDIA_BROKEN_URL_TEMPLATE','https://en.wikipedia.org/wiki/{0}')
1011

1112
def fetch_wikipedia_pages_info(page_ids, database):
1213
"""Fetched page information such as title, URL, and image thumbnail URL for the provided page IDs.
@@ -44,7 +45,7 @@ def fetch_wikipedia_pages_info(page_ids, database):
4445
# Identify this client as per Wikipedia API guidelines.
4546
# https://www.mediawiki.org/wiki/API:Main_page#Identifying_your_client
4647
headers = {
47-
'User-Agent': 'Six Degrees of Wikipedia/1.0 (https://www.sixdegreesofwikipedia.com/; [email protected])',
48+
'User-Agent': WIKIPEDIA_USER_AGENT,
4849
}
4950

5051
req = requests.get(WIKIPEDIA_API_URL, params=query_params, headers=headers)
@@ -69,7 +70,7 @@ def fetch_wikipedia_pages_info(page_ids, database):
6970
pages_info[page_id] = {
7071
'id': page_id,
7172
'title': page_title,
72-
'url': 'https://en.wikipedia.org/wiki/{0}'.format(page_title)
73+
'url': WIKIPEDIA_BROKEN_URL_TEMPLATE.format(page_title)
7374
}
7475
else:
7576
pages_info[page_id] = {

0 commit comments

Comments
 (0)