-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearches.py
66 lines (60 loc) · 1.56 KB
/
searches.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import webbrowser
import sys
# --- | (1) Simple command program for multiple searches (with parameters)| ---
# Example of using
# >python searches.py cat dog parrot
# Upper line will search for results of 'cat' and 'dog' and 'parrot'
# >python searches.py cat dog + big
# Upper line will search for results of 'big cat' and 'big dog'
# >python searches.py cat dog + big + red
# Upper line will search for results 'big cat red' and 'big dog red'
# For easier implementation I will just use Google
browser = 'google'
# This will not be implemented in command program
specified_browser = 'chrome'
# All words
words = sys.argv
#print(words)
arguments = ""
before = ""
after = ""
# Delete first item in list
words.pop(0)
#print(words)
# Combine into words
#words = words.split()
# Now we will seperate words looking for '+'
start = 0
counter = 0
i = 0
while i < len(words):
#print(words[i])
if words[i] == '+':
start += 1
if start == 0:
arguments += ' ' + words[i]
counter += 1
if start == 1:
before += ' ' + words[i]
if start == 2:
after += ' ' + words[i]
if start == 3:
break
i += 1
#print(i)
if before != '':
before = before[1:]
if after != '':
after = after[3:]
print(after)
# Combine words
def combineWords(words):
for word in words:
if '+' in word:
word = word.replace('+', ' ')
combineWords(words)
# Words before and after will be seperated with '+'
i = 0
while i < counter:
webbrowser.open(f"https://google.com/search?q={before}+{words[i]}+{after}")
i += 1