diff -r 496e094f4734 Tools/scripts/google.py --- a/Tools/scripts/google.py Thu Apr 21 00:23:08 2016 -0700 +++ b/Tools/scripts/google.py Fri Apr 29 18:45:33 2016 -0300 @@ -1,23 +1,30 @@ #! /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 = [] +Command line usage: + python google.py [search terms] +""" + +import sys +import urllib.parse +import webbrowser + +def main(args): + """Open google with search results for args. + + *args* is a iterable of strings with search terms. + """ + + query_args = [] for arg in args: - if '+' in arg: - arg = arg.replace('+', '%2B') if ' ' in arg: arg = '"%s"' % arg - arg = arg.replace(' ', '+') - list.append(arg) - s = '+'.join(list) - url = "http://www.google.com/search?q=%s" % s + query_args.append(urllib.parse.quote_plus(arg)) + + query = '+'.join(query_args) + url = "https://www.google.com/search?q=%s" % query webbrowser.open(url) if __name__ == '__main__': - main() + main(sys.argv[1:])