"""
@author: luojunhui
"""


def article_crawler_duplicate_filter(new_article_title, db_client) -> bool:
    """
    filter duplicate article title
    :param: new_article_title
    :return: True or False
    """
    select_sql = f"""
        select article_id from crawler_meta_article where title = '{new_article_title}';
    """
    if hasattr(db_client, "fetch"):
        response = db_client.fetch(select_sql)
    elif hasattr(db_client, "select"):
        response = db_client.select(select_sql)
    else:
        raise AttributeError("db_client must has fetch or select method")

    if response:
        return True
    else:
        return False


def video_crawler_duplicate_filter(new_video_title, db_client) -> bool:
    """
    filter duplicate video title
    :param: new_video_title
    :return: True or False
    """
    select_sql = f"""
        select article_title from publish_single_video_source where article_title = '{new_video_title}';
    """
    if hasattr(db_client, "fetch"):
        response = db_client.fetch(select_sql)
    elif hasattr(db_client, "select"):
        response = db_client.select(select_sql)
    else:
        raise AttributeError("db_client must has fetch or select method")

    if response:
        return True
    else:
        return False



