Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1cd53f6

Browse files
committed
Issue #26830: Refactor Tools/scripts/google.py
Patch by Francisco Couzo.
1 parent 40465eb commit 1cd53f6

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

Tools/scripts/google.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
#! /usr/bin/env python3
22

3-
import sys, webbrowser
3+
"""Script to search with Google
44
5-
def main():
6-
args = sys.argv[1:]
7-
if not args:
8-
print("Usage: %s querystring" % sys.argv[0])
9-
return
10-
list = []
11-
for arg in args:
12-
if '+' in arg:
13-
arg = arg.replace('+', '%2B')
5+
Usage:
6+
python3 google.py [search terms]
7+
"""
8+
9+
import sys
10+
import urllib.parse
11+
import webbrowser
12+
13+
14+
def main(args):
15+
def quote(arg):
1416
if ' ' in arg:
1517
arg = '"%s"' % arg
16-
arg = arg.replace(' ', '+')
17-
list.append(arg)
18-
s = '+'.join(list)
19-
url = "http://www.google.com/search?q=%s" % s
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)
2022
webbrowser.open(url)
2123

2224
if __name__ == '__main__':
23-
main()
25+
main(sys.argv[1:])

0 commit comments

Comments
 (0)