def add_contents(content_list, rss_source):
    if content_list and rss_source:
        source_id = rss_source['id']
        new_content_list = list(
            filter(lambda content: sync_exist(content['id'])[0][0] == 0,
                   content_list))
        if not new_content_list:
            pass
        pre_sql = "INSERT INTO rss_content(id, source_id, author, title, summary, updated, link, content) VALUES "
        content_sql_list = []  # 更新的文章 sql

        [
            content_sql_list.append(
                "('%s', %s, '%s', '%s', '%s', '%s', '%s', '%s')" %
                (item['id'], source_id, item['author'], item['title'],
                 item['summary'], item['updated'], item['link'],
                 item['content'][0]['value'].replace("\'", "\'\'")))
            for item in new_content_list
        ]
        if not content_sql_list:
            return None
        # 字符串转移
        sql = "%s%s;" % (pre_sql, ",".join(content_sql_list))
        with open("insert.sql", "w") as file:
            temp_sql = sql
            file.write(temp_sql)
        db_manager.do(lambda cursor: cursor.execute(sql))
        return new_content_list
def add_rss_source(name, url):
    sql = "INSERT INTO rss_list (name, url, updated) VALUES ('%s', '%s', '');" % (
        name, url)
    print(sql)
    db_manager.do(lambda cursor: cursor.execute(sql))
def update_rss_source(rss_source):
    sql = "UPDATE rss_list SET name = '%s', url = '%s', updated = '%s' WHERE id = %s;" % (
        rss_source['name'], rss_source['url'], rss_source['updated'],
        rss_source['id'])
    db_manager.do(lambda cursor: cursor.execute(sql))
def clear_rss_source():
    db_manager.do(lambda cursor: cursor.execute("DELETE FROM rss_list;"))
def remove_rss_source(id):
    sql = "DELETE FROM rss_list WHERE id = %s;" % id
    print(sql)
    db_manager.do(lambda cursor: cursor.execute(sql))