diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2016-09-14 07:59:27 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2016-09-14 07:59:27 (GMT) |
commit | 1cd53f61006c61fe67b09117ca2aa5308607ca53 (patch) | |
tree | 1460c331635f22dcef07cc580a9a78d10bf50b18 /Tools/scripts | |
parent | 40465ebc27ec4ec86de055d5de0fc23a4da1205a (diff) | |
download | cpython-1cd53f61006c61fe67b09117ca2aa5308607ca53.zip cpython-1cd53f61006c61fe67b09117ca2aa5308607ca53.tar.gz cpython-1cd53f61006c61fe67b09117ca2aa5308607ca53.tar.bz2 |
Issue #26830: Refactor Tools/scripts/google.py
Patch by Francisco Couzo.
Diffstat (limited to 'Tools/scripts')
-rwxr-xr-x | Tools/scripts/google.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/Tools/scripts/google.py b/Tools/scripts/google.py index 12152bb..82fb287 100755 --- a/Tools/scripts/google.py +++ b/Tools/scripts/google.py @@ -1,23 +1,25 @@ #! /usr/bin/env python3 -import sys, webbrowser +"""Script to search with Google -def main(): - args = sys.argv[1:] - if not args: - print("Usage: %s querystring" % sys.argv[0]) - return - list = [] - for arg in args: - if '+' in arg: - arg = arg.replace('+', '%2B') +Usage: + python3 google.py [search terms] +""" + +import sys +import urllib.parse +import webbrowser + + +def main(args): + def quote(arg): if ' ' in arg: arg = '"%s"' % arg - arg = arg.replace(' ', '+') - list.append(arg) - s = '+'.join(list) - url = "http://www.google.com/search?q=%s" % s + return urllib.parse.quote_plus(arg) + + qstring = '+'.join(quote(arg) for arg in args) + url = urllib.parse.urljoin('https://www.google.com/search', '?q=' + qstring) webbrowser.open(url) if __name__ == '__main__': - main() + main(sys.argv[1:]) |