示例#1
0
    def run(self, execution_context, app_context):
        """run the action"""
        opening_reacts = app_context.get_config('behavior.weather_react.opening')
        tts.say_random(opening_reacts)

        # get weather info
        weather = dynamic_facts.get_weather()
        main_weather = weather['weather'][0]['main']
        clouds = weather['clouds']['all']
        temp = weather['main']['temp'] - 273 # convert from Kelvin
        pressure = weather['main']['pressure']
        humidity = weather['main']['humidity']

        react_config = app_context.get_config('behavior.weather_react')

        main_weather_react = react_config.get('main.' + main_weather, [])
        clouds_react = react_config.get('clouds', [])
        temp_react = react_config.get('temp', [])
        pressure_react = react_config.get('pressure', [])
        humidity_react = react_config.get('humidity', [])

        tts.say_random_finish(main_weather_react, execution_context)
        tts.say_random(clouds_react, {'clouds' : clouds})
        tts.say_random(temp_react, {'temp' : int(temp)})
        tts.say_random(pressure_react, {'pressure' : pressure})
        tts.say_random(humidity_react, {'humidity' : humidity})
示例#2
0
文件: react.py 项目: kdung/jenova
    def run(self, execution_context):
        event_name = execution_context.event_name
        config_name = 'behavior.react.' + event_name.split('.')[1]
        reacts = self.get_config(config_name)
        if reacts is None or len(reacts) == 0:
            execution_context.finish('No react for ' + config_name)
            return

        tts.say_random_finish(reacts, execution_context)
示例#3
0
文件: base.py 项目: kdung/jenova
 def run(self, execution_context):
     event_name = execution_context.event_name.split('.')[1]
     config_name = 'behavior.inquire.' + event_name
     reacts = self.get_config(config_name)
     txt_no_data = self.get_config('behavior.inquire.no_data')
     if reacts is None or len(reacts) == 0:
         LOGGER.warning('No behavior configured for ' + config_name)
         tts.say_random_finish(txt_no_data, execution_context)
         return
     tts.say_random_finish(reacts, execution_context)
示例#4
0
    def run(self, execution_context):
        interests = self.get_config('facts.tokenized_interests')
        has_interest_react = self.get_config('behavior.interest_react.yes')
        no_interest_react = self.get_config('behavior.interest_react.no')
        tagged_text = execution_context.event.get('tagged_text')

        for word in tagged_text:
            if word[1] == 'JJ' or word[1] == 'NN' or word[1] == 'NNS':
                if word[0] in interests:
                    tts.say_random_finish(has_interest_react, execution_context)
                    return

        tts.say_random_finish(no_interest_react, execution_context)
示例#5
0
    def run(self, execution_context, app_context):
        """run the action"""
        lang = app_context.get_config('behavior.news_react.lang')
        tweet_count = app_context.get_config('behavior.news_react.count')
        opening = app_context.get_config('behavior.news_react.opening')

        tts.say_random(opening)

        # get all tweets from user timeline
        tweets = twitter.get_statuses(tweet_count)

        # filter tweets by language
        tweets = [tweet for tweet in tweets if tweet['user']['lang'] == lang]

        if len(tweets) == 0:
            no_news_reacts = app_context.get_config(
                'behavior.news_react.no_data')
            tts.say_random_finish(no_news_reacts, execution_context)
            return

        # get random tweets
        rand_tweet = tweets[random.randint(0, len(tweets) - 1)]

        new_tmpl = app_context.get_config('behavior.news_react.templates')

        text = tts.get_random(new_tmpl, {
            'text': rand_tweet['text'],
            'user': rand_tweet['user']['name']
        })
        execution_context.finish(text)

        tts.say_random(app_context.get_config('behavior.news_react.has_data'))

        # filter URL & hashtags
        text = re.sub(r'http\S+', '', text)
        if not lang == 'en':
            text = re.sub(r'#\S+', '', text)

        tts.say([text])
示例#6
0
    def run(self, execution_context, app_context):
        """run the action"""
        no_song_react = app_context.get_config('behavior.sing.no_song')

        songs = app_context.get_config('songs')
        song_id = execution_context.event.get('song_id', None)
        tagged_text = execution_context.event.get('tagged_text', None)
        tagged_text = self.filter_tagged_text(tagged_text, app_context)
        song = None

        if song_id is None and len(tagged_text) > 0:
            # there are song name mentioned in tagged text. find it
            song = self.find_tagged_song(songs, tagged_text)
            if song is None:
                tts.say_random_finish(no_song_react, execution_context)
                return
        else:
            song = self.find_song(songs, song_id)

        if song is not None:
            execution_context.finish('singing ' + song.get('name'))
            self.sing_the_song(song)
        else:
            tts.say_random_finish(no_song_react, execution_context)
示例#7
0
    def run(self, execution_context):
        # opening = app.get_config('behavior.entity_react.opening')
        no_data_react = self.get_config('behavior.entity_react.no_data')
        confused_react = self.get_config('behavior.entity_react.confused')
        not_support_react = self.get_config(
            'behavior.entity_react.not_support')

        inquire_type = execution_context.event_name.split('.')[2]
        tagged_text = execution_context.event.get('tagged_text')
        entity_name = [
            w[0] for w in tagged_text if w[1] == 'NN' or w[1] == 'JJ'
        ]

        file_names = get_file_names(entity_name)
        no_files = len(file_names)

        # not found
        if no_files == 0:
            tts.say_random_finish(no_data_react, execution_context)
            return

        # duplicates found
        if no_files > 1:
            entitie_names = [get_entity_name(f) for f in file_names]
            tts.say_random_finish(confused_react, execution_context, {
                'count': no_files,
                'entities': ', '.join(entitie_names)
            })
            return

        entity = get_entity(file_names[0])
        # not supported
        if inquire_type not in entity:
            tts.say_random_finish(not_support_react, execution_context)
            return
        info = entity[inquire_type]
        execution_context.finish(info)
        tts.say([info])