File: ripbang

package info (click to toggle)
qutebrowser 3.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,432 kB
  • sloc: python: 72,411; javascript: 31,862; sh: 874; xml: 149; makefile: 52
file content (28 lines) | stat: -rwxr-xr-x 823 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
#
# Adds DuckDuckGo bang as searchengine.
#
# Usage:
#   :spawn --userscript ripbang [bang]...
#
# Example:
#   :spawn --userscript ripbang amazon maps
#

import os, requests, sys

for argument in sys.argv[1:]:
    bang = '!' + argument
    r = requests.get('https://html.duckduckgo.com/html/',
                     allow_redirects=False,
                     params={'q': bang + ' SEARCHTEXT'},
                     headers={'user-agent': 'qutebrowser ripbang'})

    searchengine = r.headers['location']
    searchengine = searchengine.replace('SEARCHTEXT', '{}')

    if os.getenv('QUTE_FIFO'):
        with open(os.environ['QUTE_FIFO'], 'w') as fifo:
            fifo.write('config-dict-add url.searchengines %s %s' % (bang, searchengine))
    else:
        print('%s %s' % (bang, searchengine))