Ejemplo n.º 1
0
# coding=utf-8
__author__ = 'fengoupeng'

import MySQLdb, traceback
import threading

from logs import LogHandler

log = LogHandler('pymysql')


class PyMySQL(object):

    FETCH_ONE = 0
    FETCH_MANY = 1
    FETCH_ALL = 2

    SELECT_SQL_FORMAT = "SELECT %s FROM `%s` WHERE %s"
    INSERT_SQL_FORMAT = "INSERT INTO `%s` (%s) VALUES (%s)"
    UPDATE_SQL_FORMAT = "UPDATE `%s` SET %s WHERE %s"
    DETELE_SQL_FORMAT = "DELETE FROM `%s` WHERE %s"

    def __init__(self, host, post, database, username, password):
        self.conn = None
        self.host = host
        self.post = post
        self.database = database
        self.username = username
        self.password = password
        self._connect()
Ejemplo n.º 2
0
from rasa.utils.endpoints import EndpointConfig
from rasa.core.agent import Agent
import asyncio
from rasa.core.tracker_store import MongoTrackerStore
from rasa.core.domain import Domain
import logging
from logs import LogHandler
from config import ConfigManager as CM

# setup logging
ErrorLogger = logging.getLogger("ErrorLogs")
InfoLogger = logging.getLogger("InfoLogs")
LogHandler.setup_logging()

domain = Domain.load('domain.yml')
modelPath = CM.rasa_model_path
action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")

agent = Agent.load(str(modelPath),
                   action_endpoint=action_endpoint,
                   tracker_store=MongoTrackerStore(domain=domain))


async def parse(text, senderId):
    global agent
    response = await agent.handle_text(text, sender_id=senderId)
    return response


def get_bot_response(userMsg, senderId):
    response = None
Ejemplo n.º 3
0
import json
import os
import re
import sys
import time
import traceback

import redis

sys.path.append('..')

import tools
from logs import LogHandler
from pymysql import PyMySQL

logger = LogHandler('statistics')


def stat_fail_task():
    try:
        from i_scheduler.conf import redis_tasks
        redis_db = redis.Redis(
            host=redis_tasks['host'],
            port=redis_tasks['port'],
            db=redis_tasks['database'],
            password=redis_tasks['password'],
        )
        fail_tasks = redis_db.lrange(redis_tasks['key'], 0, -1)
        stat_dict = {}
        for fail_task in fail_tasks:
            json_task = json.loads(fail_task)