diff options
author | Florian Bruhin <git@the-compiler.org> | 2017-09-29 13:38:38 +0200 |
---|---|---|
committer | Florian Bruhin <git@the-compiler.org> | 2017-09-29 13:39:09 +0200 |
commit | 74e1b1ec26594f444d26e42450b7a43afe76d22a (patch) | |
tree | aac9b434cde2fdbb039353eefab759346a33ec79 | |
parent | cfe7386f2035dda483d7342072b696d1c921e7c1 (diff) | |
download | qutebrowser-74e1b1ec26594f444d26e42450b7a43afe76d22a.tar.gz qutebrowser-74e1b1ec26594f444d26e42450b7a43afe76d22a.zip |
Make userscripts work on both Python 2 and 3
(cherry picked from commit dca962ca037cf8adea3512464402463fb651a998)
-rwxr-xr-x | misc/userscripts/readability | 2 | ||||
-rwxr-xr-x | misc/userscripts/ripbang | 15 |
2 files changed, 12 insertions, 5 deletions
diff --git a/misc/userscripts/readability b/misc/userscripts/readability index 2de4be5ab..7a956c057 100755 --- a/misc/userscripts/readability +++ b/misc/userscripts/readability @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # # Executes python-readability on current page and opens the summary as new tab. # diff --git a/misc/userscripts/ripbang b/misc/userscripts/ripbang index 4b418443d..b35ff7777 100755 --- a/misc/userscripts/ripbang +++ b/misc/userscripts/ripbang @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # # Adds DuckDuckGo bang as searchengine. # @@ -8,14 +8,21 @@ # Example: # :spawn --userscript ripbang amazon maps # -import os, re, requests, sys, urllib + +from __future__ import print_function +import os, re, requests, sys + +try: + from urllib.parse import unquote +except ImportError: + from urllib import unquote for argument in sys.argv[1:]: bang = '!' + argument r = requests.get('https://duckduckgo.com/', params={'q': bang + ' SEARCHTEXT'}) - searchengine = urllib.unquote(re.search("url=[^']+", r.text).group(0)) + searchengine = unquote(re.search("url=[^']+", r.text).group(0)) searchengine = searchengine.replace('url=', '') searchengine = searchengine.replace('/l/?kh=-1&uddg=', '') searchengine = searchengine.replace('SEARCHTEXT', '{}') @@ -24,4 +31,4 @@ for argument in sys.argv[1:]: with open(os.environ['QUTE_FIFO'], 'w') as fifo: fifo.write('set searchengines %s %s' % (bang, searchengine)) else: - print '%s %s' % (bang, searchengine) + print('%s %s' % (bang, searchengine)) |