stack_overflow: Pass API query parameters as params
dict in requests.get().
This commit is contained in:
parent
a38917723a
commit
86ffbb2b4a
|
@ -1,6 +1,12 @@
|
||||||
{
|
{
|
||||||
"request": {
|
"request": {
|
||||||
"api_url":"http://api.stackexchange.com/2.2/search/advanced?order=desc&sort=relevance&site=stackoverflow&title=narendra"
|
"api_url":"http://api.stackexchange.com/2.2/search/advanced",
|
||||||
|
"params": {
|
||||||
|
"order": "desc",
|
||||||
|
"sort": "relevance",
|
||||||
|
"site": "stackoverflow",
|
||||||
|
"title": "narendra"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
"data": {
|
"data": {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
{
|
{
|
||||||
"request": {
|
"request": {
|
||||||
"api_url":"http://api.stackexchange.com/2.2/search/advanced?order=desc&sort=relevance&site=stackoverflow&title=what%20is%20flutter"
|
"api_url":"http://api.stackexchange.com/2.2/search/advanced",
|
||||||
|
"params": {
|
||||||
|
"order": "desc",
|
||||||
|
"sort": "relevance",
|
||||||
|
"site": "stackoverflow",
|
||||||
|
"title": "what is flutter"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
"data": {
|
"data": {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
{
|
{
|
||||||
"request": {
|
"request": {
|
||||||
"api_url":"http://api.stackexchange.com/2.2/search/advanced?order=desc&sort=relevance&site=stackoverflow&title=113"
|
"api_url":"http://api.stackexchange.com/2.2/search/advanced",
|
||||||
|
"params": {
|
||||||
|
"order": "desc",
|
||||||
|
"sort": "relevance",
|
||||||
|
"site": "stackoverflow",
|
||||||
|
"title": "113"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
"data": {
|
"data": {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
{
|
{
|
||||||
"request": {
|
"request": {
|
||||||
"api_url":"http://api.stackexchange.com/2.2/search/advanced?order=desc&sort=relevance&site=stackoverflow&title=restful"
|
"api_url":"http://api.stackexchange.com/2.2/search/advanced",
|
||||||
|
"params": {
|
||||||
|
"order": "desc",
|
||||||
|
"sort": "relevance",
|
||||||
|
"site": "stackoverflow",
|
||||||
|
"title": "restful"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
"data": {
|
"data": {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
{
|
{
|
||||||
"request": {
|
"request": {
|
||||||
"api_url":"http://api.stackexchange.com/2.2/search/advanced?order=desc&sort=relevance&site=stackoverflow&title=Zulip"
|
"api_url":"http://api.stackexchange.com/2.2/search/advanced",
|
||||||
|
"params": {
|
||||||
|
"order": "desc",
|
||||||
|
"sort": "relevance",
|
||||||
|
"site": "stackoverflow",
|
||||||
|
"title": "Zulip"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
"data": {
|
"data": {
|
||||||
|
|
|
@ -45,11 +45,15 @@ class StackOverflowHandler(object):
|
||||||
if query == '' or query == 'help':
|
if query == '' or query == 'help':
|
||||||
return help_text
|
return help_text
|
||||||
|
|
||||||
query_stack_link = ('http://api.stackexchange.com/2.2/search/advanced?'
|
query_stack_url = 'http://api.stackexchange.com/2.2/search/advanced'
|
||||||
'order=desc&sort=relevance&site=stackoverflow&title=%s'
|
query_stack_params = dict(
|
||||||
% (urllib.parse.quote(query),))
|
order='desc',
|
||||||
|
sort='relevance',
|
||||||
|
site='stackoverflow',
|
||||||
|
title=query
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
data = requests.get(query_stack_link)
|
data = requests.get(query_stack_url, params=query_stack_params)
|
||||||
|
|
||||||
except requests.exceptions.RequestException:
|
except requests.exceptions.RequestException:
|
||||||
logging.error('broken link')
|
logging.error('broken link')
|
||||||
|
|
Loading…
Reference in a new issue