Issue #26830: Refactor Tools/scripts/google.py

Patch by Francisco Couzo.
This commit is contained in:
Berker Peksag 2016-09-14 10:59:27 +03:00
parent 40465ebc27
commit 1cd53f6100
1 changed files with 17 additions and 15 deletions

View File

@ -1,23 +1,25 @@
#! /usr/bin/env python3 #! /usr/bin/env python3
import sys, webbrowser """Script to search with Google
def main(): Usage:
args = sys.argv[1:] python3 google.py [search terms]
if not args: """
print("Usage: %s querystring" % sys.argv[0])
return import sys
list = [] import urllib.parse
for arg in args: import webbrowser
if '+' in arg:
arg = arg.replace('+', '%2B')
def main(args):
def quote(arg):
if ' ' in arg: if ' ' in arg:
arg = '"%s"' % arg arg = '"%s"' % arg
arg = arg.replace(' ', '+') return urllib.parse.quote_plus(arg)
list.append(arg)
s = '+'.join(list) qstring = '+'.join(quote(arg) for arg in args)
url = "http://www.google.com/search?q=%s" % s url = urllib.parse.urljoin('https://www.google.com/search', '?q=' + qstring)
webbrowser.open(url) webbrowser.open(url)
if __name__ == '__main__': if __name__ == '__main__':
main() main(sys.argv[1:])