Beispiel #1
0
    def headlines(self, x, y):

        for i in range(x, y):
            headlines = (self.news[i])['title']
            gui.display('\n' + headlines)
            talk(headlines)
            headlines = headlines.lower()
            self.lit.append(headlines)
Beispiel #2
0
    def question(self):
        gui.display('\n please, let me help you')
        talk('please, let me help you')

        question = command()

        res = self.clint.query(question)

        answer = next(res.results).text

        gui.display('\n' + answer)
        talk(answer)
Beispiel #3
0
    def synonym(self, text):
        de_word = [
            "what", 'is', 'are', 'the', 'synonyms', 'synonym', 'of', "a", "?",
            ".", ","
        ]
        word = get_stem(text, de_word)

        synonym = self.dictionary.synonym(word)
        gui.display(word.upper() + ':--')
        talk('synonyms of ' + word + ' are ')
        for i in range(len(synonym)):
            gui.display(str(i + 1) + ') ' + synonym[i])
            talk(synonym[i])
Beispiel #4
0
    def __init__(self):

        self.greet = True

        self.dictionary = Dictionary()
        self.question = Ask_question()
        self.open_in_browser = Open_in_browser()
        self.weather = Weather()
        self.news = News()
        self.maths = Mathparse()
        self.word_game = WordGame()

        pid = os.getpid()
        gui.display(pid)
Beispiel #5
0
def command():

    try:
        with sr.Microphone() as source:
            gui.display('\tlistening...\n')
            voice = listener.listen(source)
            command = listener.recognize_google(voice)
            command = command.lower()

    except:
        command = 'none'

    gui.display('->> ' + command + '\n')
    return command
Beispiel #6
0
def initials():
    global name

    try:
        with sr.Microphone() as source:
            gui.display("...\n")
            voice = listener.listen(source)
            recognise_name = listener.recognize_google(voice)
            recognise_name = recognise_name.lower()

    except Exception:
        recognise_name = 'none'

    if name.lower() in recognise_name:
        return True
Beispiel #7
0
    def perform_task(self):

        typ, command = self.get_task()

        if typ == "response":
            gui.display(command + "\n")
            talk(command)

        elif typ == "close":
            self.close()

        elif typ == 'time':
            time = datetime.datetime.now().strftime('%I:%M:%p')
            gui.display('\n' + time)
            talk('the time is ' + time.replace(':', ''))

        elif typ == "wikisearch":
            wikisearch = command.replace('who is', '')
            info = wikipedia.summary(wikisearch, 2)
            gui.display('\n' + info)
            talk(info)

        elif typ == "meaning":
            self.dictionary.meaning(command)

        elif typ == "antonym":
            self.dictionary.antonym(command)

        elif typ == "synonym":
            self.dictionary.synonym(command)

        elif typ == "wolframalpha":
            self.question.question()

        elif typ == "url":
            self.open_in_browser.open_url(command)

        elif typ == "open site":
            self.open_in_browser.open_special(command)

        elif typ == "youtube":
            self.open_in_browser.play_in_yt(command)

        elif typ == "weather":
            self.weather.get_weather()

        elif typ == "maths":
            self.maths.solve(command)

        elif typ == 'news':
            self.news.get_news()

        elif typ == 'word_game':
            self.word_game.play()

        elif typ == "none":
            gui.display('\n' + 'sorry I did not get you')
            talk('sorry I did not get you')
Beispiel #8
0
    def solve(self, statement):

        de_word = ['mathparse']
        statement = get_stem(statement, de_word)

        statement = statement.replace("to the power", "^")
        statement = statement.replace("into", "*")
        statement = statement.replace("multiplied by", "*")
        statement = statement.replace("divided by", "/")
        statement = statement.replace("by", "/")

        expression = mathparse.extract_expression(statement, language='ENG')
        ans = mathparse.parse(expression)

        gui.display(f"{expression} = {ans}")
        talk(f"{expression} = {ans}")
Beispiel #9
0
    def open_url(self, topic):

        de_word = ['open', 'the', 'site', 'url']
        topic = get_stem(topic, de_word)
        url = 'https://' + topic

        if self.validator(url):
            gui.display('\n' + url)
            webbrowser.open(url)
            de_word = ['https://', 'www.', '.com', '.in']
            for w in de_word:
                if w in url:
                    url = url.replace(w, '')
            talk('opening ' + url)
        else:
            gui.display('\nSorry!  Invalid url!')
            talk('Sorry! Invalid u r l')
Beispiel #10
0
    def get_weather(self):
        response = requests.get(self.complete_url)
        x = response.json()
        if x["cod"] != "404":
            y = x["main"]
            current_temperature = int(y["temp"] - 273)
            current_humidiy = y["humidity"]
            z = x["weather"]
            weather_description = z[0]["description"]

            gui.display('\nWEATHER REPORT -')
            talk('current weather report is as follows')

            gui.display(" Temperature = " + str(current_temperature) + "°С" +
                        "\n Humidity = " + str(current_humidiy) + "(%)" +
                        "\n Description = " + str(weather_description) + '\n')

            talk("Temperature is " + str(current_temperature) +
                 "degree celcius" + "\n Humidity is " + str(current_humidiy) +
                 " percent"
                 "\n and, it is " + str(weather_description))
Beispiel #11
0
    def play_in_yt(self, topic):

        de_word = ["open", "in", 'youtube', 'play', 'on', 'play_yt', '_yt']
        topic = get_stem(topic, de_word)

        url = 'https://www.youtube.com/results?q=' + topic
        count = 0
        cont = requests.get(url)
        data = cont.content
        data = str(data)
        lst = data.split('"')
        for i in lst:
            count += 1
            if i == 'WEB_PAGE_TYPE_WATCH':
                break
        if lst[count - 5] == "/results":
            raise Exception("No video found.")

        #print("Videos found, opening most recent video")
        webbrowser.open("https://www.youtube.com" + lst[count - 5])

        talk('playing' + topic)
        gui.display(f"playing {topic}")
Beispiel #12
0
    def meaning(self, text):

        de_word = [
            "what", 'is', 'are', 'the', 'meanings', 'meaning', 'of', "a", "?",
            ".", ","
        ]
        word = get_stem(text, de_word)

        meaning = self.dictionary.meaning(word)
        gui.display(word.upper() + ':--')
        talk('meanings of ' + word + ' are ')
        key = list(meaning)
        for i in range(len(meaning)):
            gui.display(key[i] + ' -')
            talk('as a ' + key[i])
            v = meaning[key[i]]
            for e in range(len(v)):
                gui.display('\n' + str(e + 1) + ') ' + v[e])
                talk(v[e])

            gui.display('\n')
Beispiel #13
0
    def greatings(self):

        hour = datetime.datetime.now().hour
        if hour >= 0 and hour < 12:
            gui.display('\n' + "Hello,Good Morning\n")
            talk("Hello, Good Morning")
            talk("How may I help you?")

        elif hour >= 12 and hour < 16:
            gui.display('\n' + "Hello,Good Afternoon\n")
            talk("Hello, Good Afternoon")
            talk("How may I help you?")

        else:
            gui.display("Hello,Good Evening\n")
            talk("Hello, Good Evening")
            talk("How may I help you?")
Beispiel #14
0
    def close(self):

        hour = datetime.datetime.now().hour

        if hour >= 21 or hour <= 2:
            gui.display('\n' + "Good Night, Sleep Tight," +
                        "\n Don't Let The Bed Bugs Bight")
            talk("Good night sleep tight, don't let the bed bugs bight")
            gui.stop()
            exit()  # closes perform_task

        elif hour > 2 and hour < 4:
            gui.display('\n Abee soo jaa BSDK')
            talk('Abee so jaa B S D K')
            gui.stop()
            exit()  # closes perform_task

        else:
            gui.display('\n' + 'See you later, Alligator')
            talk('See you later, Alligator')
            gui.stop()
            exit()  # closes perform_task
Beispiel #15
0
    def get_news(self):

        gui.display("today's news headlines are :")
        talk("today's news headlines are")

        self.headlines(0, 5)

        gui.display('do you want more news headlines?')
        talk('do you want more headlines?')
        reply = command()

        if 'yes' in reply:
            self.headlines(5, 10)
            gui.display('do you want more details?')
            talk('do you want more details?')
            reply = command()

            if 'tell me more about' in reply:
                self.details(reply)
                gui.display("that's all for current news headlines")
                talk("that's all for current news headlines")

            else:
                gui.display("that's all for current news headlines")
                talk("that's all for current news headlines")

        elif 'tell me more about' in reply:
            self.details(reply)
            gui.display("that's all for current news headlines")
            talk("that's all for current news headlines")

        else:
            gui.display("that's all for current news headlines")
            talk("that's all for current news headlines")
Beispiel #16
0
    def open_special(self, topic):

        de_word = ['open']
        site = get_stem(topic, de_word)

        if 'amazon' in site:
            url = 'https://www.amazon.in/'
            webbrowser.open(url)
            gui.display('\n' + url)
            talk('opening' + site)

        if 'google' in site:
            url = 'https://www.google.com/'
            webbrowser.open(url)
            gui.display('\n' + url)
            talk('opening' + site)

        if 'facebook' in site:
            url = 'https://www.facebook.com/'
            webbrowser.open(url)
            gui.display('\n' + url)
            talk('opening' + site)

        if 'facebook' in site:
            url = 'https://www.facebook.com/'
            webbrowser.open(url)
            gui.display('\n' + url)
            talk('opening' + site)

        if 'reddit' in site:
            url = 'https://www.reddit.com/'
            webbrowser.open(url)
            gui.display('\n' + url)
            talk('opening' + site)

        if 'github' in site:
            url = 'https://www.github.com/'
            webbrowser.open(url)
            gui.display('\n' + url)
            talk('opening' + site)

        else:
            gui.display('\nSorry! I am currently limited in my capablities')
            talk('Sorry! I am currently limited in my capablities')
Beispiel #17
0
    def play(self):

        gui.display("Wellcome to Word Game. Let's play")
        talk("Wellcome to Word Game. Let's play")

        while self.playing:

            compword = self.rw.get_random_word(hasDictionaryDef="true")
            self.compwords.append(compword)
            gui.display(compword)
            talk(compword)

            reply = command()

            if reply != 'none':

                if self.dic.meaning(reply) != None:

                    if compword[-1] == reply[0]:

                        if reply not in self.playerwords and reply not in self.compwords:
                            self.playerwords.append(reply)

                        else:
                            gui.display("you used that word already")
                            talk("you used that word already")
                            gui.display("you loose")
                            talk("you loose")
                            self.playing = False

                    else:
                        gui.display("Against the rule, you loose")
                        talk("Against the rule, you loose")
                        self.playing = False

                else:
                    gui.display("Not a Real Word, You loose")
                    talk("Not a Real Word, You loose")
                    self.playing = False

            else:
                gui.display('Too late!! You loose')
                talk("too late, you loose")
                self.playing = False
Beispiel #18
0
    def details(self, text):

        if 'exit' not in text:
            topic = text.replace('tell me more about ', '')
            for i in range(len(self.lit)):
                if topic in self.lit[i]:
                    description = (self.news[i])['description']
                    gui.display(description)
                    talk(description)

                    gui.display('do you want more details?')
                    talk('do you want more details?')
                    reply = command()
                    if 'tell me more about' in reply:
                        self.details(reply)

                    elif 'no' in reply:
                        gui.display("that's all for current news headlines")
                        talk("that's all for current news headlines")

                    else:
                        gui.display('sorry I did not get you')
                        talk('sorry I did not get you')
                        gui.display('please repeat')
                        talk('please repeat')
                        reply = command()
                        self.details(reply)

                else:
                    if i + 1 == len(self.lit):
                        gui.display('sorry I did not get you')
                        talk('sorry I did not get you')
                        gui.display('please repeat')
                        talk('please repeat')
                        reply = command()
                        self.details(reply)