2013-10-15 20:51:35 +02:00
|
|
|
from json import loads
|
|
|
|
|
|
|
|
def request(query, params):
|
|
|
|
params['url'] = 'http://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=%s&srprop=timestamp&format=json' % query
|
|
|
|
|
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
def response(resp):
|
|
|
|
search_results = loads(resp.text)
|
|
|
|
results = []
|
2013-10-16 23:21:04 +02:00
|
|
|
res = search_results.get('query', {}).get('search', [])
|
|
|
|
if len(res):
|
|
|
|
results.append({'url': 'https://en.wikipedia.org/wiki/%s' % res[0]['title'].replace(' ', '_'), 'title': res[0]['title']})
|
2013-10-15 20:51:35 +02:00
|
|
|
return results
|
|
|
|
|