|
| 1 | +import wolframalpha |
| 2 | +client = wolframalpha.Client("3647V2-7GHV2X2VL4") |
| 3 | +import wikipedia |
| 4 | +import PySimpleGUI as sg |
| 5 | + |
| 6 | +sg.theme('BrownBlue') |
| 7 | +layout = [ [sg.Text('Enter a Command '), sg.InputText()], |
| 8 | + [sg.Button('Ok'), sg.Button('Cancel')] ] |
| 9 | + |
| 10 | +# Create the Window |
| 11 | +window = sg.Window('Robo', layout) |
| 12 | + |
| 13 | +while True: |
| 14 | + event, values = window.read() |
| 15 | + |
| 16 | + if event in (None, 'Cancel'): # if user closes window or clicks cancel |
| 17 | + break |
| 18 | + |
| 19 | + import pyttsx3 |
| 20 | + engine = pyttsx3.init() |
| 21 | + |
| 22 | + try: |
| 23 | + wiki_res = wikipedia.summary(values[0], sentences=2) |
| 24 | + res = client.query(values[0]) |
| 25 | + wolfram_res = next(res.results).text |
| 26 | + sg.PopupNonBlocking("Wolfram Result : " + wolfram_res, "Wikipedia Result :" + wiki_res) |
| 27 | + engine.say(wolfram_res) |
| 28 | + engine.say(wiki_res) |
| 29 | + |
| 30 | + |
| 31 | + except wikipedia.exceptions.DisambiguationError: |
| 32 | + res = client.query(values[0]) |
| 33 | + wolfram_res = next(res.results).text |
| 34 | + sg.PopupNonBlocking("Wolfram Result : " + wolfram_res) |
| 35 | + engine.say(wolfram_res) |
| 36 | + |
| 37 | + |
| 38 | + except wikipedia.exceptions.PageError: |
| 39 | + res = client.query(values[0]) |
| 40 | + wolfram_res = next(res.results).text |
| 41 | + sg.PopupNonBlocking("Wolfram Result : " + wolfram_res) |
| 42 | + engine.say(wolfram_res) |
| 43 | + |
| 44 | + |
| 45 | + except: |
| 46 | + wiki_res = wikipedia.summary(values[0], sentences=2) |
| 47 | + sg.PopupNonBlocking("Wikipedia Result : " + wiki_res) |
| 48 | + engine.say(wiki_res) |
| 49 | + |
| 50 | + |
| 51 | + engine.runAndWait() |
| 52 | + |
| 53 | + |
| 54 | +window.close() |
0 commit comments