duckduckgo_definitions.py 567 B

12345678910111213141516171819
  1. import json
  2. from searx import base_result_template
  3. def request(query, params):
  4. params['url'] = 'http://api.duckduckgo.com/?q=%s&format=json&pretty=0' % query
  5. return params
  6. def response(resp):
  7. search_res = json.loads(resp.text)
  8. results = []
  9. if 'Definition' in search_res:
  10. res = {'title' : search_res.get('Heading', '')
  11. ,'content' : search_res.get('Definition', '')
  12. ,'url' : search_res.get('AbstractURL', '')
  13. }
  14. results.append(base_result_template.format(**res))
  15. return results