wikipedia: Pass API query parameters as params dict in requests.get().

This commit is contained in:
novokrest 2018-05-11 08:09:22 +03:00 committed by Tim Abbott
parent 8654ce53db
commit bccbda49f2
7 changed files with 50 additions and 10 deletions

View file

@ -1,6 +1,12 @@
{
"request": {
"api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=%23&format=json"
"api_url":"https://en.wikipedia.org/w/api.php",
"params": {
"action": "query",
"list": "search",
"srsearch": "#",
"format": "json"
}
},
"response": {
"data": {

View file

@ -1,6 +1,12 @@
{
"request": {
"api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=sssssss%20kkkkk&format=json"
"api_url":"https://en.wikipedia.org/w/api.php",
"params": {
"action": "query",
"list": "search",
"srsearch": "sssssss kkkkk",
"format": "json"
}
},
"response": {
"data": {

View file

@ -1,6 +1,12 @@
{
"request": {
"api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=The%20sky%20is%20blue&format=json"
"api_url":"https://en.wikipedia.org/w/api.php",
"params": {
"action": "query",
"list": "search",
"srsearch": "The sky is blue",
"format": "json"
}
},
"response": {
"data": {

View file

@ -1,6 +1,12 @@
{
"request": {
"api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=123&format=json"
"api_url":"https://en.wikipedia.org/w/api.php",
"params": {
"action": "query",
"list": "search",
"srsearch": "123",
"format": "json"
}
},
"response": {
"data": {

View file

@ -1,6 +1,12 @@
{
"request": {
"api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=happy&format=json"
"api_url":"https://en.wikipedia.org/w/api.php",
"params": {
"action": "query",
"list": "search",
"srsearch": "happy",
"format": "json"
}
},
"response": {
"data": {

View file

@ -1,7 +1,13 @@
{
"request": {
"api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=Zulip&format=json"
"api_url":"https://en.wikipedia.org/w/api.php",
"params": {
"action": "query",
"list": "search",
"srsearch": "Zulip",
"format": "json"
}
},
"response": {
"data": {

View file

@ -47,11 +47,15 @@ class WikipediaHandler(object):
if query == '':
return help_text
query_wiki_link = ('https://en.wikipedia.org/w/api.php?action=query&'
'list=search&srsearch=%s&format=json'
% (urllib.parse.quote(query),))
query_wiki_url = 'https://en.wikipedia.org/w/api.php'
query_wiki_params = dict(
action='query',
list='search',
srsearch=query,
format='json'
)
try:
data = requests.get(query_wiki_link)
data = requests.get(query_wiki_url, params=query_wiki_params)
except requests.exceptions.RequestException:
logging.error('broken link')