コード例 #1
0
def main():
    """ Функция получает тело запроса и возвращает ответ

    :return: ответ
    """
    alice_request = AliceRequest(request.json)
    logging.info('Request: {}'.format(alice_request))
    alice_response = AliceResponse(alice_request)
    user_id = alice_request.user_id
    alice_response, session_storage[user_id] = handle_dialog(
        alice_request, alice_response, session_storage.get(user_id))
    logging.info('Response: {}'.format(alice_response))
    return alice_response.dumps()
コード例 #2
0
ファイル: alice_app.py プロジェクト: FunFunFine/ProjectSix
def main():
    alice_request = AliceRequest(request.json)
    logging.info('Request: {}'.format(alice_request))

    alice_response = AliceResponse(alice_request)

    user_id = alice_request.user_id

    alice_response, SESSION_STORAGE[user_id] = handle_dialog(
        alice_request, alice_response, SESSION_STORAGE.get(user_id)
    )

    logging.info('Response: {}'.format(alice_response))

    return alice_response.dumps()
コード例 #3
0
def main():
    database = init_database(host='localhost', user='******', password='******', dbname='new_game')
    alice_request = AliceRequest(request.json)
    logging.info('Request: {}'.format(alice_request))
    alice_response = AliceResponse(alice_request)

    user_id = alice_request.user_id
    alice_response, session_storage[user_id] = handle_dialog(
        alice_request, alice_response, session_storage.get(user_id), database
    )

    logging.info('Response: {}'.format(alice_response))
    print()

    return alice_response.dumps()
コード例 #4
0
def post():
    with open('users.pickle', 'rb') as file:
        users = pickle.load(file)

    alice_request = AliceRequest(request.json)
    user_id = alice_request.user_id

    if alice_request.is_new_session:
        users[user_id] = AliceDialog()  # Создаем новый диалог

    alice_response = users[user_id].handle_dialog(alice_request)
    if users[user_id].response.is_end:
        users.pop(user_id)

    with open('users.pickle', 'wb') as file:
        pickle.dump(users, file)

    return alice_response.dumps()
コード例 #5
0
def main():
    # Функция получает тело запроса и возвращает ответ.
    alice_request = AliceRequest(request.json)
    logging.info('Request: {}'.format(alice_request))
    database = database_module.DatabaseManager()
    alice_response = AliceResponse(alice_request)

    user_id = alice_request.user_id
    print(user_id)
    print(session_storage.get(user_id))
    print(len(session_storage))
    alice_response, session_storage[user_id] = handle_dialog(
        alice_request, alice_response, session_storage.get(user_id), database)

    logging.info('Response: {}'.format(alice_response))
    print()

    return alice_response.dumps()
コード例 #6
0
def main():
    alice_request = AliceRequest(request.json)
    logging.info('Request: {}'.format(alice_request))

    alice_response = AliceResponse(alice_request)

    user_id = alice_request.user_id

    alice_response, storage = handle_dialog(
        alice_request, alice_response,
        mc.get("session_storage").get(user_id))

    sessions = mc.get("session_storage")
    sessions[user_id] = storage
    mc.set("session_storage", sessions)

    logging.info('Response: {}'.format(alice_response))

    return alice_response.dumps()
コード例 #7
0
def main():
    with open("sessions.json", encoding="utf8") as file:
        session_storage = json.loads(file.read())

    alice_request = AliceRequest(request.json)
    # logging.info("Request: {}".format(alice_request))

    alice_response = AliceResponse(alice_request)

    user_id = alice_request.user_id

    alice_response, session_storage[user_id] = handle_dialog(
        alice_request, alice_response, session_storage.get(user_id))

    with open("sessions.json", "w", encoding="utf8") as file:
        json.dump(session_storage, fp=file)

    logging.info("Response: {}".format(alice_response))

    return alice_response.dumps()
コード例 #8
0
ファイル: alice_app.py プロジェクト: R31N3/life_simulation
def main():
    database = init_database(host='localhost', user='******', password='******',
                             dbname='programmer_simulator')

    # Функция получает тело запроса и возвращает ответ.
    alice_request = AliceRequest(request.json)
    logging.info('Request: {}'.format(alice_request))

    alice_response = AliceResponse(alice_request)

    user_id = alice_request.user_id
    print(user_id)
    print(session_storage.get(user_id))
    print(len(session_storage))
    alice_response, session_storage[user_id] = handle_dialog(
        alice_request, alice_response, session_storage.get(user_id), database
    )

    logging.info('Response: {}'.format(alice_response))
    print()

    return alice_response.dumps()
コード例 #9
0
def mainnn():
    from other import main_function
    from other import alice_app
    import pymorphy2
    database = alice_app.init_database(host='localhost', user='******', password='******', dbname='word_coach')
    alice_request = AliceRequest(request.json)
    morph = pymorphy2.MorphAnalyzer()
    logging.info('Request: {}'.format(alice_request))
    alice_response = AliceResponse(alice_request)

    user_id = alice_request.user_id
    print(user_id)
    print(session_storage.get(user_id))
    print(len(session_storage))
    alice_response, session_storage[user_id] = main_function.handle_dialog(
        alice_request, alice_response, session_storage.get(user_id), database, morph
    )

    logging.info('Response: {}'.format(alice_response))
    print()

    return alice_response.dumps()
コード例 #10
0
def main():
    # Функция получает тело запроса и возвращает ответ.
    with open("sessions.json", encoding="utf8") as file:
        session_storage = json.loads(file.read())

    alice_request = AliceRequest(request.json)
    # logging.info("Request: {}".format(alice_request))

    alice_response = AliceResponse(alice_request)

    user_id = alice_request.user_id

    alice_response, session_storage[user_id] = handle_dialog(
        alice_request, alice_response, session_storage.get(user_id))

    # Потому что оперативка плохо работает
    with open("sessions.json", "w", encoding="utf8") as file:
        json.dump(session_storage, fp=file)

    logging.info("Response: {}".format(alice_response))

    return alice_response.dumps()
コード例 #11
0
def zavalinka():
    from other2 import database_module
    from other2 import zavalinka
    import pymorphy2
    from other2.alice_sdk import AliceRequest, AliceResponse
    morph = pymorphy2.MorphAnalyzer()
    database = database_module.DatabaseManager()
    # Функция получает тело запроса и возвращает ответ.
    alice_request = AliceRequest(request.json)
    logging.info('Request: {}'.format(alice_request))

    alice_response = AliceResponse(alice_request)

    user_id = alice_request.user_id
    print(user_id)
    print(session_storage.get(user_id))
    print(len(session_storage))
    alice_response, session_storage[user_id] = zavalinka.handle_dialog(
        alice_request, alice_response, session_storage.get(user_id), database, morph.parse('очко')[0]
    )

    logging.info('Response: {}'.format(alice_response))

    return alice_response.dumps()
コード例 #12
0
async def main(request):
    request = AliceRequest(await request.body())
    response = request.create_response()
    response.set_message(do_something())
    logging.info(request)
    return JSONResponse(response.body())
コード例 #13
0
def book(request: AliceRequest, response: AliceResponse, user_storage):
    if not user_storage.get("buy-status"):
        user_storage["buy-status"] = BuyStatus.Choosing
        user_storage["composers"] = composers.copy()
        return send_response(response, user_storage, "select-concert")

    if user_storage.get("buy-status") == BuyStatus.Selected:
        user_storage.pop("buy-status")
        return send_response(response,
                             user_storage,
                             "concert-selected",
                             add_variants=False)

    last_names = request.get_last_names()

    if len(last_names):
        user_storage["composers"] &= last_names

    logging.debug(
        f"Composers for request {' '.join(user_storage['composers'])}")

    if len(user_storage["composers"]) == 0:
        user_storage["composers"] = composers.copy()
        return send_response(response, user_storage,
                             "select-concert-composer-unknown")

    # I'm really feel sorry for this code
    # but working with time sucks
    # working with time ranges sucks twice

    start_date = datetime.date.today()
    end_date = None
    if request.has_date():
        logging.debug("has dates")
        dates = request.get_date()
        start = dates[0]
        if "month_is_relative" in start:
            month = None
            if start["month_is_relative"] == True:
                month_add = start["month"]
                if month_add < 0:
                    return send_response(response, user_storage,
                                         "select-concert-empty")
                month = max(1, (datetime.date.today().month + month_add) % 13)
                logging.debug("relative time")
            else:
                month = start["month"]
                logging.debug("non relative time")
            if month in [11, 12]:
                start_date = datetime.date(2018, month, 1)
            elif month < 5:
                start_date = datetime.date(2019, month, 1)
            else:
                return send_response(response, user_storage,
                                     "select-concert-empty")
            end_date = last_day_in_month(start_date)

    start_date = max(start_date, datetime.date.today())
    logging.debug(f"start date: {humanize.naturalday(start_date)}")
    if end_date:
        logging.debug(f"end date: {humanize.naturalday(end_date)}")

    concerts = find_concerts(user_storage["composers"], start_date, end_date)

    if concerts.empty:
        return send_response(response, user_storage, "select-concert-empty")
    logging.debug(f"found: {concerts.shape[0]} concerts")

    text = f"{'Нашлось' if len(concerts) > 1 else 'Нашёлся'} {len(concerts)} {right_form_from_number('концерт', len(concerts))}. Скажи номер понравившегося!\n"
    buttons = []

    for i, (_, concert) in enumerate(concerts.iterrows()):
        i += 1
        day = concert["дата, гггг-мм-дд"]
        buttons.append({
            "title": str(i),
            "url": concert["купить билет"],
            "hide": True
        })
        text += f"\n{i}. {concert['title']}, {day.day}.{day.month}.{day.year}"

    response.set_text(text)
    response.set_buttons(buttons)
    user_storage["buy-status"] = BuyStatus.Selected
    return response, user_storage