2010-03-11 18:53:45 -04:00
|
|
|
#! /usr/bin/env python3
|
2001-12-04 11:23:47 -04:00
|
|
|
|
2016-09-14 04:59:27 -03:00
|
|
|
"""Script to search with Google
|
2001-12-04 11:23:47 -04:00
|
|
|
|
2016-09-14 04:59:27 -03:00
|
|
|
Usage:
|
|
|
|
python3 google.py [search terms]
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import urllib.parse
|
|
|
|
import webbrowser
|
|
|
|
|
|
|
|
|
|
|
|
def main(args):
|
|
|
|
def quote(arg):
|
2001-12-04 11:23:47 -04:00
|
|
|
if ' ' in arg:
|
|
|
|
arg = '"%s"' % arg
|
2016-09-14 04:59:27 -03:00
|
|
|
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)
|
2001-12-04 11:23:47 -04:00
|
|
|
webbrowser.open(url)
|
|
|
|
|
2004-08-09 14:27:55 -03:00
|
|
|
if __name__ == '__main__':
|
2016-09-14 04:59:27 -03:00
|
|
|
main(sys.argv[1:])
|