File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33"""
44
55import 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/; wenger.jacob@gmail.com)' )
10+ WIKIPEDIA_BROKEN_URL_TEMPLATE = os . environ . get ( 'WIKIPEDIA_BROKEN_URL_TEMPLATE' , 'https://en.wikipedia.org/wiki/{0}' )
1011
1112def 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/; wenger.jacob@gmail.com)' ,
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 ] = {
You can’t perform that action at this time.
0 commit comments