• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /usr/bin/env python3
2
3"""Script to search with Google
4
5Usage:
6    python3 google.py [search terms]
7"""
8
9import sys
10import urllib.parse
11import webbrowser
12
13
14def main(args):
15    def quote(arg):
16        if ' ' in arg:
17            arg = '"%s"' % arg
18        return urllib.parse.quote_plus(arg)
19
20    qstring = '+'.join(quote(arg) for arg in args)
21    url = urllib.parse.urljoin('https://www.google.com/search', '?q=' + qstring)
22    webbrowser.open(url)
23
24if __name__ == '__main__':
25    main(sys.argv[1:])
26