wikipedia.py 488 B

123456789101112131415
  1. from json import loads
  2. def request(query, params):
  3. params['url'] = 'http://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=%s&srprop=timestamp&format=json' % query
  4. return params
  5. def response(resp):
  6. search_results = loads(resp.text)
  7. results = []
  8. for res in search_results.get('query', {}).get('search', []):
  9. results.append({'url': 'https://en.wikipedia.org/wiki/%s' % res['title'].replace(' ', '_'), 'title': res['title']})
  10. return results