0
0
mirror of https://github.com/python/cpython.git synced 2024-11-27 23:47:29 +01:00
cpython/Tools/scripts/google.py
Berker Peksag 1cd53f6100 Issue #26830: Refactor Tools/scripts/google.py
Patch by Francisco Couzo.
2016-09-14 10:59:27 +03:00

26 lines
501 B
Python
Executable File

#! /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:])