Exemple #1
0
def get_place():
    """ Get detailed information about the place """
    place = request.headers.get('place')
    if not place:
        return error_message('Not params get')
    logger.info(f'Get detailed info about {place}')
    place_info, score = get_detailed_info(place_name=place)
    logger.info(f'Score: {score*100:.2f}%')
    if score != 0.0:
        return jsonify(dict(status='success', **place_info))
    return error_message('There is no such a place.')
Exemple #2
0
def transfer_tnc(addressTo, value):
    passwd = request.headers.get("Password")
    remote_ip = request.headers.get("X-Real-IP")
    passwd_hash = setting.PASSWD_HASH
    address_from = setting.FUNDING_ADDRESS
    privt_key = setting.PRIVTKEY
    res = verify_password(passwd, passwd_hash)
    app_logger.info(remote_ip)
    if remote_ip == setting.REMOTE_ADDR and res:
        return service.token_swap(address_from, addressTo, value, privt_key)
    return {}
Exemple #3
0
def get_menu():
    """ Send menu of the place to download """
    place = request.headers.get('place')
    if not place:
        return error_message('Not params get')
    logger.info(f'Get menu of {place}')
    menu_path, score = get_menu_from_place(place_name=place)
    logger.info(f'Score: {score*100:.2f}%')
    if score != 0.0:
        try:
            return send_file(menu_path, attachment_filename='menu.pdf')
        except Exception as e:
            logger.exception(e)
            return error_message('Internal server error.')
    return error_message('There is no such a place.')
Exemple #4
0
def get_detailed_info(place_name: str) -> Tuple[dict, float]:
    """
    GEt detailed information from the database about the place
    :param place_name: name of the place to search
    :return: detailed information fro the database, probability of searched place
    """
    score = 1.0
    with DBPlaces() as db:
        info = db.get_info_place_from_name(place_name=place_name.lower())
        if not info:
            logger.info(f'There is no exact match. Go into the relative search of {place_name}')
            all_places = db.get_places(['name'])
            place_name, score = get_most_probably_name(need_place=place_name, places=[x[0] for x in all_places])
            if score == 0.0:
                return {}, score
            info = db.get_info_place_from_name(place_name=place_name)
    return info, score
Exemple #5
0
def send_message(api_id, message, branch, gitlab_project):
    """
    Try to get chat data from DB
    Check mute status
    Get branches for filtering
    If gitlab_project have a branch then looking for a match
    Send message
    :param api_id: uniq ID of chat
    :param message: text message
    :param branch: branch from hook
    :param gitlab_project: summary project from hook
    :return:
    """
    try:
        telegram_chat = N3TelegramChat.objects.get(api_id=api_id)
    except N3TelegramChat.DoesNotExist:
        return

    if is_mute(telegram_chat):
        return

    #TODO remake it!
    is_send = True
    branch_filters = []
    for project in telegram_chat.projects:
        if project.get('id') == gitlab_project.get('id'):
            branch_filters = project.get('branches')
            break

    if branch and branch_filters:
        is_send = False
        for project_branch in branch_filters:
            if fnmatch(branch, project_branch):
                is_send = True
                break

    if is_send:
        response = n3robot_bot.send_message(
            chat_id=telegram_chat.chat_id,
            text=message,
            parse_mode='Markdown',
            disable_web_page_preview=True,
            timeout=60,
            disable_notification=is_silent(telegram_chat))
        app_logger.info(response)
Exemple #6
0
def get_menu_from_place(place_name: str) -> Tuple[List[str], float]:
    """
    Get path to the menu of the place
    :param place_name: name of the place to search menu of
    :return: full path to the menu file, probability of searched place
    """
    score = 1.0
    with DBPlaces() as db:
        place_id = db.get_place_from_name(place_name=place_name.lower())
        if not place_id:
            logger.info(f'There is no exact match. Go into the relative search of {place_name}')
            all_places = db.get_places(['name'])
            place_name, score = get_most_probably_name(need_place=place_name, places=[x[0] for x in all_places])
            if score == 0.0:
                return [], score
            place_id = db.get_place_from_name(place_name=place_name)
        menus = db.get_menus_from_place_id(place_id=place_id)
    return [path_join(MENUS_DIR, str(place_id), menu_file) for menu_file in menus], score
def read_and_insert_books(books_dir="files/books"):
    """
    Reads and inserts books from the books directory
    :param books_dir Books directory
    """
    app_logger.info(f"Reading books from directory {books_dir}")

    if not current_app.elasticsearch:
        app_logger.error(f"Elasticsearch unavailable")
        return

    reset_index("library", Book)

    # read books directory
    for book in os.listdir(books_dir):
        app_logger.info(f"Reading file {book}")
        file_path = os.path.abspath(f"{books_dir}/{book}")
        # parse the book file
Exemple #8
0
def get_tokens_of_owner(contract, owner, page):
    owner = checksum_encode(owner)
    if contract.lower() == "0x06012c8cf97bead5deae237070f9587f8e7a266d":
        tokens = get_tokens_from_open_sea(contract, owner, page)
        tokens = [{
            "tokenId":
            token.get("token_id"),
            "icon":
            "https://img.cryptokitties.co/0x06012c8cf97bead5deae237070f9587f8e7a266d/{}.png"
            .format(token.get("token_id")),
            "data": {
                "cooldownIndex": token.get("traits")[0].get("value"),
                "generation": token.get("traits")[1].get("value"),
            }
        } for token in tokens]

    else:
        app_logger.info("{}{}{}".format(contract, owner, page))
        tokens = get_tokens_from_ethscan(contract, owner, page)
        tokens = [{"tokenId": str(token), "data": {}} for token in tokens]

    return tokens
Exemple #9
0
def get_places():
    """ Send menu of the place to download """
    places = get_all_places()
    logger.info('Get all places from the database')
    return jsonify({'status': 'success', 'places': places})
Exemple #10
0
#         user = UserAccount(email=email, password=password, username=email)
#         try:
#             db.session.add(user)
#             db.session.commit()
#         except IntegrityError:
#             app_logger.exception("Failed to save user with email :{}".format(email))
#

# @manager.option('-e', '--email', help='email address', required=True)
# def user_del(email):
#     """delete a user from the database"""
#     from app.mod_auth.models import UserAccount
#     user_account = UserAccount.query.filter_by(email=email)
#     if user_account:
#         db.session.delete(user_account)
#         app_logger.info("User with email: {} deleted".format(email))
#     else:
#         app_logger.error("User with email: {} does not exist in DB".format(email))


# @manager.command
# def drop_db():
#     """drop all databases, instantiate schemas"""
#     db.reflect()
#     db.drop_all()
#

if __name__ == "__main__":
    app_logger.info("Running application...")
    manager.run()