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