Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: dfa645a65ec0788d98851130a217e029d1cc4e9b authored by Ɓukasz Langa on 13 July 2020, 12:11:53 UTC
Python 3.8.4
Tip revision: dfa645a
google.py
#! /usr/bin/env python3

"""Script to search with Google

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
        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(sys.argv[1:])
back to top