예제 #1
0
def run(username, flow):
    logger.debug('Run invoked')
    data = lib.get_flowdata(username, flow)
    print(data)
    # data = [(u'weather:Brooklyn, NY',), (u'news:3',), (u'norris:3',), (u'news:2',), (u'thecocktail:random',), (u'thecocktail:random',)]
    logger.debug("Data from DB(actionline):" + str(data))
    if not data:  # len(data) == 0:
        return jsonify(
            error="no data for this user and flow",
            username=username,
            flow=flow,
            time=datetime.datetime.now()
        )

    simple_list = []
    for idx, line in enumerate(data):
        actionline = line[0]
        logger.debug("Actionline: " + str(actionline))
        action_data = lib.run_action(actionline)
        simple_list.append({
            "action": idx,
            "type": actionline.split(":")[0],
            "data": action_data
        })

    logger.debug("Action data" + str(action_data))
    return jsonify(
        username=username,
        flow=flow,
        time=datetime.datetime.now(),
        data=simple_list
    )
예제 #2
0
def run_user(username):
    logger.debug('Run invoked')
    flow = "goodmorning"
    data = lib.get_flowdata(username, flow)
    print(data)
    logger.debug("Data from DB(actionline):" + str(data))
    if not data:
        return jsonify(
            error="no data for this user and flow",
            username=username,
            flow=flow,
            time=datetime.datetime.now()
        )

    simple_list = []
    for idx, line in enumerate(data):
        actionline = line[0]
        logger.debug("Actionline: " + str(actionline))
        action_data = lib.run_action(actionline)
        simple_list.append({
            "action": idx,
            "type": actionline.split(":")[0],
            "data": action_data
        })

    logger.debug("Action data" + str(action_data))
    return jsonify(
        username=username,
        flow=flow,
        time=datetime.datetime.now(),
        data=simple_list
    )
예제 #3
0
def run(username, flow):
    data = lib.get_flowdata(username, flow)
    # data = [(u'news:3', 1), (u'norris:3', 2)]
    # print(data)
    if not data:  # len(data) == 0:
        return jsonify(error="no data for this user and flow",
                       username=username,
                       flow=flow,
                       time=datetime.datetime.now())

    simple_list = []
    for idx, line in enumerate(data):
        actionline = line[0]
        action_data = lib.run_action(actionline)
        simple_list.append({
            "action": idx,
            "type": actionline.split(":")[0],
            "data": action_data
        })

    # simpleList = []
    # for line in data:
    #     actionline = line[0]
    #     action_data = lib.run_action(actionline)
    #     simple_list.append(action_data)

    return jsonify(username=username,
                   flow=flow,
                   time=datetime.datetime.now(),
                   data=simple_list)
예제 #4
0
def send_echo(message):
    """ print(user_name, user_id, user_fullname, message.text"""
    user = message.from_user
    logger.debug("user: "******"user_name: " + str(user_name))
    user_id = user.id
    logger.debug("user_id: " + str(user_id))
    user_fullname = user.first_name + ' ' + str(user.last_name)
    print(user_name, user_id, user_fullname, message.text)

    if (message.text.lower() == 'goodmorning'):
        person = "Alex"
        logger.debug("Start flowdata")
        data = lib.get_flowdata(person, message.text.lower())
        logger.debug("Obtain flowdata")
        content = lib.get_nice_text_from_flows(data)
        logger.debug("Start obtaining information")
        bot.send_message(message.chat.id, content)
        logger.debug("Message to a bot: " + content)

    elif (message.text.lower() == 'good morning'):
        logger.debug(
            "Message to change from good morning to goodmorning in a telegram text"
        )
        bot.send_message(message.chat.id,
                         "Good morning flow for " + str(user_id))

    else:
        bot.send_message(message.chat.id, message.text)
예제 #5
0
def run(username, flow):
    logger.debug('run invoked')
    data = lib.get_flowdata(username, flow)

    simple_list = []
    for idx, line in enumerate(data):
        actionline = line
        action_data = lib.run_action(actionline)

        simple_list.append({
            "action": idx,
            "type": actionline.split(":")[0],
            "data": action_data
        })
    logger.debug("Action_data: " + str(action_data))
    return jsonify(username=username,
                   flow=flow,
                   time=datetime.datetime.now(),
                   data=simple_list)
예제 #6
0
def run(username, flow):
    logger.debug('run invoked')
    data = lib.get_flowdata(username, flow)
    # print(data)
    # data = [u'news:3', u'norris:3', u'coctail:random', u'weather:Brooklyn, NY']
    # data = [(u'weather:Brooklyn, NY',), (u'news:3',), (u'norris:3',), (u'news:2',), (u'thecocktail:random',), (u'thecocktail:random',)]
    # logger.debug("data from DB:" + str(data))
    # if not data:  # len(data) == 0:
    #     return jsonify(
    #         error="no data for this user and flow",
    #         username=username,
    #         flow=flow,
    #         time=datetime.datetime.now()
    #     )

    simple_list = []
    for idx, line in enumerate(data):
        actionline = line
        # print(actionline)
        action_data = lib.run_action(actionline)
        # print(action_data)
        simple_list.append({
            "action": idx,
            "type": actionline.split(":")[0],
            "data": action_data
        })

    # simpleList = []
    # for line in data:
    #     actionline = line[0]
    #     action_data = lib.run_action(actionline)
    #     simple_list.append(action_data)
    # weather_data =lib.run_weather(action)
    logger.debug("action data" + str(action_data))
    return jsonify(username=username,
                   flow=flow,
                   time=datetime.datetime.now(),
                   data=simple_list)