Example #1
0
    def on_event(self, event, sender):
        """
        Activates winston and returns a random, personalized greeting
        """
        if self.match(event['text']):
            current_hour = datetime.now().time().hour
            period = 'day'
            if current_hour > 4 and current_hour < 12:
                period = 'morning'
            elif current_hour > 12 and current_hour < 17:
                period = 'afternoon'
            elif current_hour > 16 and current_hour < 5:
                period = 'night'

            greetings = (
                'Good %s' % period,
                'Good %s, sir' % period,
                'Good %s, sir. I missed your presence.' % period,
                'Greetings sir',
                'Greetings sir. Is there anything I can do for you?',
                'Hello sir',
                'Hello sir. I missed you.',
                'Hello sir. What can I do for you?',
            )
            text_to_speech(choice(greetings))
Example #2
0
    def on_event(self, event, sender):
        """
        Reads the date or the time
        """
        if self.match(event['text']):
            if("time") in event['text']:
                time = datetime.now().time()
                hours = time.hour
                minutes = time.minute

                intro = (
                    'The time is',
                    'It is',
                    'It currently is',
                    'The current time is',
                )
                readable_time = "{0} {1} {2}".format(choice(intro), spell_integer(hours), spell_integer(minutes))
                text_to_speech(readable_time)
            else:
                intro = (
                    'The date is',
                    'Today is',
                )
                date = datetime.now().strftime("%B %d")
                readable_date = "{0} {1}".format(choice(intro), date)
                text_to_speech(readable_date)
Example #3
0
    def on_event(self, event, sender):
        """
        Sets an alarm
        """
        if self.match(event['text']):
            # Remove the clutter
            when = event['text'].replace(' minutes', '')
            when.replace(' from now', '')

            #Parse the number
            if "hours" in when:
                command = 'echo python {script} "{message}" | at now + {time} hours'
            else:
                command = 'echo python {script} "{message}" | at now + {time} minutes'

            messages = [
                "Sir, {time} ago, you asked me to set an alarm at this precise moment."
                .format(time=when),
                "It is time sir. You asked me to set an alarm at this precise moment {time} ago."
                .format(time=when),
            ]

            system(
                command.format(script=tts_path,
                               time=text_to_number(when),
                               message=choice(messages)))
            text_to_speech("Setting an alarm in " + when)
Example #4
0
    def on_event(self, event, sender):
        """
        Activates winston and returns a random, personalized greeting
        """
        if self.match(event['text']):
            current_hour = datetime.now().time().hour
            period = 'day'
            if current_hour > 4 and current_hour < 12:
                period = 'morning'
            elif current_hour > 12 and current_hour < 17:
                period = 'afternoon'
            elif current_hour > 16 and current_hour < 5:
                period = 'night'

            greetings = (
                'Good %s' % period,
                'Good %s, sir' % period,
                'Good %s, sir. I missed your presence.' % period,
                'Greetings sir',
                'Greetings sir. Is there anything I can do for you?',
                'Hello sir',
                'Hello sir. I missed you.',
                'Hello sir. What can I do for you?',
            )
            text_to_speech(choice(greetings))
Example #5
0
 def on_event(self, event, sender):
     """
     Reads the account balance generated by selenium-td.py. The text file
     is a human-readable string.
     """
     if self.match(event['text']):
         try:
             with open(BALANCE_PATH) as file:
                 text = file.read()
             text_to_speech(text)
         except:
             text_to_speech("I am afraid I cannot get your account balance, sorry.")
Example #6
0
    def on_event(self, event, sender):
        """
        Fetches the bus schedule using the STM API
        """
        if self.match(event['text']):
            line = 107
            stop = 56685
            direction = 'N'

            try:
                data = urlopen(BUS_SCHEDULE_URL.format(line=line,
                                                       stop=stop,
                                                       direction=direction),
                               timeout=5)
                results = load(data)['result']
            except:
                text_to_speech(
                    'Sorry, I cannot retrieve the bus schedule at the moment.')
            else:
                # Pretty-print the results
                stops = []
                cancelled_stops = []
                for result in results:
                    stop = {
                        'cancelled': result['is_cancelled'],
                        'time': strptime(result['time'], '%H%M'),
                    }

                    if stop['cancelled']:
                        cancelled_stops.append(stop)
                    else:
                        stops.append(stop)

                # Pretty-print the times
                stops = ', then at '.join(
                    [strftime('%H:%M', stop['time']) for stop in stops[:2]])

                cancelled_stops = ', then at '.join([
                    strftime('%H:%M', stop['time']) for stop in cancelled_stops
                ])

                output = ""

                if stops:
                    output = "The bus will stop at {times}.".format(
                        times=stops)
                    if cancelled_stops:
                        output += " The {times} stops were cancelled.".format(
                            times=stops)
                else:
                    output = "It appears that all stops were cancelled for the next few hours."
                print(output)
                text_to_speech(output)
Example #7
0
 def on_event(self, event, sender):
     """
     Reads the account balance generated by selenium-td.py. The text file
     is a human-readable string.
     """
     if self.match(event['text']):
         try:
             with open(BALANCE_PATH) as file:
                 text = file.read()
             text_to_speech(text)
         except:
             text_to_speech(
                 "I am afraid I cannot get your account balance, sorry.")
Example #8
0
 def on_event(self, event, sender):
     """
     Suggests a dinner idea
     """
     if self.match(event['text']):
         sentences = (
             'Would you enjoy some {0}?',
             'What about {0}',
             'I suggest {0}',
             '{0} for dinner seems like a good idea',
             'I would go for {0}',
         )
         suggestion = choice(sentences).format(self.get_dinner_idea())
         text_to_speech(suggestion)
Example #9
0
 def on_event(self, event, sender):
     """
     Deactivates winston and returns a random, personalized farewell
     """
     if self.match(event['text']):
         goodbyes = (
             'I will remain silent sir.',
             'Farewell sir',
             'I will see you later sir.',
             'See you soon sir.',
             'You will be missed, sir.',
             'Have a nice day sir',
             'I am going to sleep sir',
             'Deactivating myself sir',
         )
         text_to_speech(choice(goodbyes))
Example #10
0
 def on_event(self, event, sender):
     """
     Deactivates winston and returns a random, personalized farewell
     """
     if self.match(event['text']):
         goodbyes = (
             'I will remain silent sir.',
             'Farewell sir',
             'I will see you later sir.',
             'See you soon sir.',
             'You will be missed, sir.',
             'Have a nice day sir',
             'I am going to sleep sir',
             'Deactivating myself sir',
         )
         text_to_speech(choice(goodbyes))
Example #11
0
    def on_event(self, event, sender):
        """
        Fetches the bus schedule using the STM API
        """
        if self.match(event['text']):
            line = 107
            stop = 56685
            direction = 'N'

            try:
                data = urlopen(BUS_SCHEDULE_URL.format(line=line, stop=stop, direction=direction), timeout=5)
                results = load(data)['result']
            except:
                text_to_speech('Sorry, I cannot retrieve the bus schedule at the moment.')
            else:
                # Pretty-print the results
                stops = []
                cancelled_stops = []
                for result in results:
                    stop = {
                        'cancelled': result['is_cancelled'],
                        'time': strptime(result['time'], '%H%M'),
                    }

                    if stop['cancelled']:
                        cancelled_stops.append(stop)
                    else:
                        stops.append(stop)

                # Pretty-print the times
                stops = ', then at '.join([strftime('%H:%M', stop['time']) for stop in stops[:2]])

                cancelled_stops = ', then at '.join([strftime('%H:%M', stop['time']) for stop in cancelled_stops])
                
                output = ""
                
                if stops:
                    output = "The bus will stop at {times}.".format(times=stops)
                    if cancelled_stops:
                        output += " The {times} stops were cancelled.".format(times=stops)
                else:
                    output = "It appears that all stops were cancelled for the next few hours."
                print(output)
                text_to_speech(output)
Example #12
0
    def on_event(self, event, sender):
        """
        Sets an alarm
        """
        if self.match(event['text']):
            # Remove the clutter
            when = event['text'].replace('tomorrow', '')

            #Parse the number
            time_value = text_to_time(when)
            time_string = time_value.strftime("%H:%M")
            command = 'echo python {script} "{message}" | at -m {time}AM'

            messages = [
                "Sir, you asked me to set an alarm at this precise moment.",
                "It is time sir. You asked me to set an alarm at this precise moment.",
                "Hello sir. You asked me to wake you up at this time.",
            ]

            system(command.format(script=tts_path, time=time_string, message=choice(messages)))
            text_to_speech("Setting an alarm at " + when )
Example #13
0
    def on_event(self, event, sender):
        """
        Sets an alarm
        """
        if self.match(event['text']):
            # Remove the clutter
            when = event['text'].replace(' minutes', '')
            when.replace(' from now', '')

            #Parse the number
            if "hours" in when:
                command = 'echo python {script} "{message}" | at now + {time} hours'
            else:
                command = 'echo python {script} "{message}" | at now + {time} minutes'

            messages = [
                "Sir, {time} ago, you asked me to set an alarm at this precise moment.".format(time=when),
                "It is time sir. You asked me to set an alarm at this precise moment {time} ago.".format(time=when),
            ]

            system(command.format(script=tts_path, time=text_to_number(when), message=choice(messages)))
            text_to_speech("Setting an alarm in " + when )
Example #14
0
    def on_event(self, event, sender):
        """
        Sets an alarm
        """
        if self.match(event['text']):
            # Remove the clutter
            when = event['text'].replace('tomorrow', '')

            #Parse the number
            time_value = text_to_time(when)
            time_string = time_value.strftime("%H:%M")
            command = 'echo python {script} "{message}" | at -m {time}AM'

            messages = [
                "Sir, you asked me to set an alarm at this precise moment.",
                "It is time sir. You asked me to set an alarm at this precise moment.",
                "Hello sir. You asked me to wake you up at this time.",
            ]

            system(
                command.format(script=tts_path,
                               time=time_string,
                               message=choice(messages)))
            text_to_speech("Setting an alarm at " + when)
Example #15
0
    def on_event(self, event, sender):
        """
        Fetches and reads the weather
        """
        if self.match(event['text']):
            try:
                if self.match(event['text']):
                    if not self.last_report_time or (
                            datetime.now() -
                            self.last_report_time) > timedelta(minutes=30):
                        print("Fetching weather report from Forecast.io")
                        self.last_report = load(
                            urlopen(WEATHER_API_URL, timeout=5))
                        self.last_report_time = datetime.now()
            except:
                text_to_speech("I am afraid I cannot get the weather, sorry.")
            else:
                json = self.last_report

                current_temp = int(json['currently']['apparentTemperature'])
                min_temp = int(json['daily']['data'][0]['temperatureMin'])
                max_temp = int(json['daily']['data'][0]['temperatureMax'])
                precip_probability = int(
                    json['daily']['data'][0]['precipProbability'])
                precip_type = json['daily']['data'][0]['precipType']
                current_weather = json['daily']['data'][0]['summary']

                output = ""

                if "temperature" in event['text']:
                    output = "It is {0} degrees outside.".format(current_temp)
                elif "rain" in event['text']:
                    if precip_probability < 15:
                        answers = (
                            "Not a chance in the world, sir.",
                            "I highly doubt so.",
                            "No sir",
                            "No rainfall expected, sir.",
                            "No rain is expected today",
                            "You can leave your umbrella at home. It will not rain today.",
                        )
                        output = choice(answers)
                    else:
                        if precip_type == "rain":
                            output = "There is a {0} percent chance of rain for the day".format(
                                precip_probability)
                        else:
                            output = "There is a {0} percent chance of {1} for the day, but no rain is expected".format(
                                precip_probability, precip_type)
                elif "snow" in event['text']:
                    if precip_probability < 15:
                        answers = (
                            "Not a chance in the world, sir.",
                            "I highly doubt so.",
                            "No sir",
                            "No snowfall expected, sir.",
                            "No snow is expected today",
                        )
                        output = choice(answers)
                    else:
                        if precip_type == "snow":
                            output = "There is a {0} percent chance of snow for the day".format(
                                precip_probability)
                        else:
                            output = "There is a {0} percent chance of {1} for the day, but no snow is expected".format(
                                precip_probability, precip_type)
                else:
                    output = "{weather} with a temperature between {min} and {max}.".format(
                        weather=current_weather,
                        min=min_temp,
                        max=max_temp,
                    )

                text_to_speech(output)
Example #16
0
    def on_event(self, event, sender):
        """
        Fetches and reads the weather
        """
        if self.match(event['text']):
            try:
                if self.match(event['text']):
                    if not self.last_report_time or (datetime.now()-self.last_report_time) > timedelta(minutes=30):
                        print("Fetching weather report from Forecast.io")
                        self.last_report = load(urlopen(WEATHER_API_URL, timeout=5))
                        self.last_report_time = datetime.now()
            except:
                text_to_speech("I am afraid I cannot get the weather, sorry.")
            else:
                json = self.last_report

                current_temp = int(json['currently']['apparentTemperature'])
                min_temp = int(json['daily']['data'][0]['temperatureMin'])
                max_temp = int(json['daily']['data'][0]['temperatureMax'])
                precip_probability = int(json['daily']['data'][0]['precipProbability'])
                precip_type = json['daily']['data'][0]['precipType']
                current_weather = json['daily']['data'][0]['summary']

                output = ""

                if "temperature" in event['text']:
                    output = "It is {0} degrees outside.".format(current_temp)
                elif "rain" in event['text']:
                    if precip_probability < 15:
                        answers = (
                            "Not a chance in the world, sir.",
                            "I highly doubt so.",
                            "No sir",
                            "No rainfall expected, sir.",
                            "No rain is expected today",
                            "You can leave your umbrella at home. It will not rain today.",
                        )
                        output = choice(answers)
                    else:
                        if precip_type == "rain":
                            output = "There is a {0} percent chance of rain for the day".format(precip_probability)
                        else:
                            output = "There is a {0} percent chance of {1} for the day, but no rain is expected".format(precip_probability, precip_type)
                elif "snow" in event['text']:
                    if precip_probability < 15:
                        answers = (
                            "Not a chance in the world, sir.",
                            "I highly doubt so.",
                            "No sir",
                            "No snowfall expected, sir.",
                            "No snow is expected today",
                        )
                        output = choice(answers)
                    else:
                        if precip_type == "snow":
                            output = "There is a {0} percent chance of snow for the day".format(precip_probability)
                        else:
                            output = "There is a {0} percent chance of {1} for the day, but no snow is expected".format(precip_probability, precip_type)
                else:
                    output = "{weather} with a temperature between {min} and {max}.".format(
                        weather = current_weather,
                        min = min_temp,
                        max = max_temp,
                    )

                text_to_speech(output)