2017-09-29 13:38:38 +02:00
|
|
|
#!/usr/bin/env python
|
2016-12-25 17:50:24 +01:00
|
|
|
#
|
|
|
|
# Adds DuckDuckGo bang as searchengine.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# :spawn --userscript ripbang [bang]...
|
2017-01-02 21:53:04 +01:00
|
|
|
#
|
2016-12-25 17:50:24 +01:00
|
|
|
# Example:
|
|
|
|
# :spawn --userscript ripbang amazon maps
|
|
|
|
#
|
2017-09-29 13:38:38 +02:00
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
import os, re, requests, sys
|
|
|
|
|
|
|
|
try:
|
|
|
|
from urllib.parse import unquote
|
|
|
|
except ImportError:
|
|
|
|
from urllib import unquote
|
2016-12-25 17:50:24 +01:00
|
|
|
|
2017-01-02 21:53:04 +01:00
|
|
|
for argument in sys.argv[1:]:
|
|
|
|
bang = '!' + argument
|
|
|
|
r = requests.get('https://duckduckgo.com/',
|
|
|
|
params={'q': bang + ' SEARCHTEXT'})
|
2016-12-25 17:50:24 +01:00
|
|
|
|
2017-09-29 13:38:38 +02:00
|
|
|
searchengine = unquote(re.search("url=[^']+", r.text).group(0))
|
2017-01-02 21:53:04 +01:00
|
|
|
searchengine = searchengine.replace('url=', '')
|
|
|
|
searchengine = searchengine.replace('/l/?kh=-1&uddg=', '')
|
|
|
|
searchengine = searchengine.replace('SEARCHTEXT', '{}')
|
2016-12-25 17:50:24 +01:00
|
|
|
|
2017-01-02 21:53:04 +01:00
|
|
|
if os.getenv('QUTE_FIFO'):
|
|
|
|
with open(os.environ['QUTE_FIFO'], 'w') as fifo:
|
|
|
|
fifo.write('set searchengines %s %s' % (bang, searchengine))
|
|
|
|
else:
|
2017-09-29 13:38:38 +02:00
|
|
|
print('%s %s' % (bang, searchengine))
|