wikipedia.py 505B

12345678910111213141516
  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. res = search_results.get('query', {}).get('search', [])
  9. if len(res):
  10. results.append({'url': 'https://en.wikipedia.org/wiki/%s' % res[0]['title'].replace(' ', '_'), 'title': res[0]['title']})
  11. return results