示例#1
0
    def run(self, execution_context):
        from app import APP_INSTANCE as app
        app.reload_config()

        url = app.get_config('bot.url')
        msg = {'name': 'reload', 'args': {}}
        execution_context.finish('reload done')
        http.call(url, msg)
示例#2
0
 def run(self, execution_context, app_context):
     """run the action"""
     command = execution_context.event.get('command')
     url = app_context.get_config('bot.url')
     _, content = http.call(url, command)
     content_obj = json.loads(content.decode('utf-8'))
     execution_context.finish(content_obj['msg'])
示例#3
0
 def send_msg(self, result_word, result_proba, filtered_text, url):
     """send the message to bot"""
     msg = {
         'name': result_word,
         'args': {
             'proba': result_proba,
             'tagged_text': filtered_text
         }
     }
     return http.call(url, msg)
示例#4
0
文件: predict.py 项目: kdung/jenova
 def send_msg(self, result_word, result_proba, filtered_text):
     """send the message to bot"""
     url = self.get_config('bot.url')
     msg = {
         'name': result_word,
         'args': {
             'proba': result_proba,
             'tagged_text': filtered_text
         }
     }
     return http.call(url, msg)
示例#5
0
文件: weather.py 项目: kdung/jenova
def get_weather(city=None):
    """get weather forecast"""
    from app import APP_INSTANCE as app
    global CACHED_DATA
    time_to_live = app.get_config('api.weather.time_to_live')
    if has_cache(time_to_live):
        LOGGER.warning('Use cached weather data')
        return CACHED_DATA['CACHED_RESULT']
    app_id = app.get_config('api.weather.key')
    # TODO get city dynamically
    if city is None:
        city = app.get_config('api.weather.city')
    server_url = 'http://api.openweathermap.org/data/2.5/weather?q=' + city + '&APPID=' + app_id
    res, content = http.call(server_url, None, 'GET')
    result = json.loads(content.decode('utf-8'))
    if result is None or result.get('cod') != 200:
        LOGGER.warning('Result from api server: ' + str(content))
        return None
    CACHED_DATA['CACHED_RESULT'] = result
    CACHED_DATA['CACHED_TIME'] = time.time()
    return result