2013-10-15 19:11:43 +02:00
|
|
|
from json import loads
|
2013-10-23 23:55:37 +02:00
|
|
|
from urllib import urlencode
|
2013-10-14 23:09:13 +02:00
|
|
|
|
2013-10-23 23:55:37 +02:00
|
|
|
url = 'https://duckduckgo.com/'
|
|
|
|
search_url = url + 'd.js?{query}&l=us-en&p=1&s=0'
|
2013-10-14 23:09:13 +02:00
|
|
|
|
|
|
|
def request(query, params):
|
2013-10-23 23:55:37 +02:00
|
|
|
params['url'] = search_url.format(query=urlencode({'q': query}))
|
2013-10-14 23:09:13 +02:00
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
def response(resp):
|
2013-10-15 19:11:43 +02:00
|
|
|
results = []
|
|
|
|
search_res = loads(resp.text[resp.text.find('[{'):-2])[:-1]
|
|
|
|
for r in search_res:
|
|
|
|
if not r.get('t'):
|
|
|
|
continue
|
|
|
|
results.append({'title': r['t']
|
|
|
|
,'content': r['a']
|
|
|
|
,'url': r['u']
|
|
|
|
})
|
|
|
|
return results
|