-
Notifications
You must be signed in to change notification settings - Fork 7
/
Search.py
43 lines (33 loc) · 1.19 KB
/
Search.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
import webview
from TTS import speak
from urllib.parse import quote as encode
def get_elements(session):
# Get answer element
def get_answer():
try:
answer = session.get_elements('[data-tts="answers"]')
speak(answer[0]['outerText'])
except IndexError:
get_description()
except KeyError:
get_description()
except webview.util.WebViewException:
pass
# Get description element
def get_description():
try:
description = session.get_elements('[data-attrid="wa:/description"]')
speak(description[0]['outerText'])
except IndexError:
speak("Here are the search results for your query.")
except KeyError:
speak("Here are the search results for your query.")
get_answer()
def query(user_input: str):
search_window(encode(user_input))
def search_window(to_search: str):
window = webview.create_window('JARVIS', url='https://www.google.co.in/search?q=' + to_search)
webview.start(get_elements, window)
def open_page(url: str):
window = webview.create_window('JARVIS', url=url)
webview.start(get_elements, window)