-
Notifications
You must be signed in to change notification settings - Fork 2
/
web_functions.py
148 lines (126 loc) · 7.36 KB
/
web_functions.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import webbrowser
import wikipedia
import colorama
from speech_engine import casper_speak
from input_engine import casper_input
from chronicle_engine import chronicle_log
from message_functions import casper_alert
from colorama import Fore, Back
colorama.init(autoreset=True)
def internet_actions(command, voice_var, input_var, log):
if "search" in command.lower():
indx = command.lower().split().index("search")
conv = command.split()[indx + 1:]
query = ' '.join([str(item) for item in conv])
print(Fore.GREEN + f"Searching for {query}".center(100))
casper_speak(speak=f"searching for {query}", voice=voice_var)
webbrowser.open(f"https://www.google.com/search?q={query}")
casper_speak(speak="I found these results", voice=voice_var)
chronicle_log(write=Fore.GREEN + f"Searching Google for {query}".center(100), var=log)
chronicle_log(write="I found these results".center(100), var=log)
return
elif "youtube" in command.lower():
indx = command.lower().split().index("youtube")
conv = command.split()[indx + 1:]
yt_search = ' '.join([str(item) for item in conv])
print(Fore.GREEN + f"Searching YouTube for {yt_search}".center(100))
casper_speak(speak=f"Searching YouTube for {yt_search}", voice=voice_var)
webbrowser.open(f"https://www.youtube.com/results?search_query={yt_search}")
casper_speak(speak="I found these results", voice=voice_var)
chronicle_log(Fore.GREEN + f"Searching YouTube for {yt_search}".center(100), var=log)
chronicle_log(write="I found these results".center(100), var=log)
return
elif "Wikipedia" in command or "wiki" in command:
print(Fore.YELLOW + "What do you want to search?".center(100))
casper_speak(speak="what do you want to search?", voice=voice_var)
wiki_search = casper_input(input_src=input_var, log_var=log)
print()
print(Fore.GREEN + f"Searching wikipedia for {wiki_search}".center(100))
casper_speak(speak=f"searching wikipedia for {wiki_search}", voice=voice_var)
wiki_summary = wikipedia.summary(wiki_search, sentences=2)
centr = str(wiki_summary)
webbrowser.open(f"https://en.wikipedia.org/wiki/{wiki_search}")
print("")
print(Fore.LIGHTBLUE_EX + centr.center(100))
casper_speak(speak=f"According to wikipedia, {wiki_summary}", voice=voice_var)
chronicle_log(write=Fore.YELLOW + "What do you want to search?".center(100), var=log)
chronicle_log(write=Fore.GREEN + f"Searching wikipedia for {wiki_search}".center(100), var=log)
chronicle_log(write="", var=log)
chronicle_log(write=Fore.LIGHTBLUE_EX + centr.center(100), var=log)
return
elif "gmail" in command.lower():
print(Fore.GREEN + "Opening your Gmail account".center(100))
casper_speak(speak="Opening your Gmail account", voice=voice_var)
webbrowser.open("https://mail.google.com/")
chronicle_log(write=Fore.GREEN + "Opening your Gmail account".center(100), var=log)
return
elif "google news" in command or "gnews" in command.lower():
print(Fore.YELLOW + "What do you want to search?".center(100))
casper_speak(speak="what do you want to search?", voice=voice_var)
gnews = casper_input(input_src=input_var, log_var=log)
print()
print(Fore.GREEN + f"Searching Google News for {gnews}".center(100))
casper_speak(speak=f"searching Google News for {gnews}", voice=voice_var)
webbrowser.open(f"https://news.google.com/search?q={gnews}&hl=en-US&gl=US&ceid=US%3Aen")
casper_speak(speak="I found these results", voice=voice_var)
chronicle_log(write=Fore.GREEN + f"Searching Google News for {gnews}".center(100), var=log)
chronicle_log(write="I found these results".center(100), var=log)
return
elif "github" in command or "account" in command.lower():
print(Fore.GREEN + "Opening your GitHub account".center(100))
casper_speak(speak="Opening your GitHub account", voice=voice_var)
webbrowser.open("https://github.com/ashfaaqrifath")
chronicle_log(write=Fore.GREEN + "Opening your GitHub account".center(100), var=log)
return
elif "facebook" in command.lower():
print(Fore.GREEN + "Opening your Facebook profile".center(100))
casper_speak(speak="Opening your Facebook profile", voice=voice_var)
webbrowser.open("https://www.facebook.com/ashfaaq.rifath")
chronicle_log(write=Fore.GREEN + "Opening your Facebook profile".center(100), var=log)
return
elif "instagram" in command.lower():
print(Fore.GREEN + "Opening your Instagram profile".center(100))
casper_speak(speak="Opening your Instagram profile", voice=voice_var)
webbrowser.open("https://www.instagram.com/ashfaaqrifath/")
chronicle_log(write=Fore.GREEN + "Opening your Instagram profile".center(100), var=log)
return
elif "twitter" in command.lower():
print(Fore.GREEN + "Opening your Twitter profile".center(100))
casper_speak(speak="Opening your Twitter profile", voice=voice_var)
webbrowser.open("https://twitter.com/ashfaaqrifth")
chronicle_log(write=Fore.GREEN + "Opening your Twitter profile".center(100), var=log)
return
elif "source code" in command or "src" in command.lower():
print(Fore.GREEN + "Accessing source code from GitHub".center(100))
casper_speak(speak="Accessing source code from GitHub", voice=voice_var)
webbrowser.open("https://github.com/ashfaaqrifath/Casper")
chronicle_log(write=Fore.GREEN + "Accessing source code from GitHub".center(100), var=log)
return
elif "stack overflow" in command.lower():
print(Fore.GREEN + "Opening Stack Overflow".center(100))
casper_speak(speak="Opening Stack Overflow", voice=voice_var)
webbrowser.open("https://stackoverflow.com")
chronicle_log(write=Fore.GREEN + "Opening Stack Overflow".center(100), var=log)
return
elif "new tab" in command.lower():
webbrowser.open("https://google.com")
print(Fore.GREEN + "Opened new chrome tab".center(100))
casper_speak(speak="opened new chrome tab", voice=voice_var)
chronicle_log(write=Fore.GREEN + "Opened new chrome tab".center(100), var=log)
return
elif "incognito tab" in command or "incog tab" in command.lower():
tab = "www.google.com"
chrome_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s --incognito"
webbrowser.get(chrome_path).open_new(tab)
print(Fore.RED + "Opened Incognito tab".center(100))
casper_speak(speak="Opened Incognito tab", voice=voice_var)
chronicle_log(write=Fore.RED + "Opened Incognito tab".center(100), var=log)
casper_alert("OPENED CHROME INCOGNITO TAB")
return
elif "locate" in command.lower():
location = command.replace("locate", "")
print(Fore.GREEN + f"Locating {location}".center(100))
casper_speak(speak=f"locating {location}", voice=voice_var)
webbrowser.open(f"https://www.google.nl/maps/place/{location}")
chronicle_log(write=Fore.GREEN + f"Locating {location}".center(100), var=log)
return