import time

import pandas as pd
from sqlalchemy import create_engine
from sqlalchemy.pool import NullPool
from sqlalchemy import text
from sqlalchemy.orm import sessionmaker
import platform
import traceback
import json
import uuid
from sqlalchemy.exc import SQLAlchemyError


class ConnectSpider:
    def __init__(self):
        self.pg_port = 54328
        self.pg_db = "selection"
        self.pg_user = "postgres"
        self.pg_pwd = "F9kL2sXe81rZq"
        self.pg_host = "61.145.136.61"
        self.db_engine = create_engine(f"postgresql://{self.pg_user}:{self.pg_pwd}@{self.pg_host}:{self.pg_port}/{self.pg_db}")

        pg_host = "192.168.10.223"
        self.db_engine192 = create_engine(
            f"postgresql://{self.pg_user}:{self.pg_pwd}@{self.pg_host}:{self.pg_port}/{self.pg_db}")

        # mysql
        self.sql_port = 3306
        self.sql_db = "selection"
        self.sql_user = "adv_yswg"
        self.sql_pwd = "Gd1pGJog1ysLMLBdML8w81"
        self.sql_host = "rm-wz9yg9bsb2zf01ea4yo.mysql.rds.aliyuncs.com"
        self.charset = 'utf8mb4'

        # 创建数据库连接字符串
        connection_string_mysql = f"mysql+pymysql://{self.sql_user}:{self.sql_pwd}@{self.sql_host}:{self.sql_port}/{self.sql_db}?charset={self.charset}"
        self.mysql_engine = create_engine(connection_string_mysql)

        # mysql
        sql_port = 19030
        sql_db = "test"
        sql_user = "fangxingjun"
        sql_pwd = "fangxingjun12345"
        sql_host = "192.168.10.151"
        wai_host = "113.100.143.162"

        # 创建数据库连接字符串
        connection_string_mysql = f"mysql+pymysql://{sql_user}:{sql_pwd}@{wai_host}:{sql_port}/{sql_db}"
        self.mysql_test = create_engine(connection_string_mysql)

        # mysql
        sql_port = 19030
        sql_db = "selection"
        sql_user = "fangxingjun"
        sql_pwd = "fangxingjun12345"
        sql_host = "192.168.10.151"
        wai_host = "113.100.143.162"

        # 创建数据库连接字符串
        connection_string_mysql = f"mysql+pymysql://{sql_user}:{sql_pwd}@{sql_host}:{sql_port}/{sql_db}"
        self.mysql_selection = create_engine(connection_string_mysql)


    def mysql(self):
        sql_port = 3306
        sql_db = "us_spider"
        sql_user = "adv_yswg"
        sql_pwd = "Gd1pGJog1ysLMLBdML8w81"
        sql_host = "rm-wz9yg9bsb2zf01ea4yo.mysql.rds.aliyuncs.com"
        charset = 'utf8mb4'

        # 创建数据库连接字符串
        connection_string_mysql = f"mysql+pymysql://{sql_user}:{sql_pwd}@{sql_host}:{sql_port}/{sql_db}?charset={charset}"
        mysql_engine = create_engine(connection_string_mysql)
        return mysql_engine

    def mysql_us_spider(self):
        sql_port = 19030
        # sql_db = "us_spider"
        sql_db = "test"
        sql_user = "fangxingjun"
        sql_pwd = "fangxingjun12345"
        sql_host = "192.168.10.151"

        # 创建数据库连接字符串
        connection_string_mysql = f"mysql+pymysql://{sql_user}:{sql_pwd}@{sql_host}:{sql_port}/{sql_db}"
        mysql_us_spider_engine = create_engine(connection_string_mysql)
        return mysql_us_spider_engine



    def save_stock_img_id(self, items):
        """批量保存数据到数据库。"""
        # 提取 image_title 和 image_size_info
        processed_items = []
        for item in items:
            image_title = item.get('title', '')
            image_size_info = json.dumps(item.get('sizes', {}))
            processed_item = {
                'account_id': item['account_id'],
                'image_id': item['image_id'],
                'state': item['state'],
                'created_at': item['created_at'],
                'image_title': image_title,
                'image_size_info': image_size_info
            }
            processed_items.append(processed_item)
        # # 定义DataFrame的列 旧代码
        # columns = ['account_id', 'image_id', 'state', 'created_at', 'image_title', 'image_size_info']
        # df = pd.DataFrame(processed_items, columns=columns)
        #
        # # 使用with语句管理数据库连接
        # with self.db_engine192.connect() as connection:
        #     df.to_sql(
        #         name=table_name,
        #         con=connection,
        #         if_exists='append',
        #         index=False
        #     )
        insert_sql = text("""
        INSERT INTO stock_image_id_wj
          (account_id, image_id, state, created_at, image_title, image_size_info)
        VALUES
          (:account_id, :image_id, :state, :created_at, :image_title, :image_size_info)
        ON CONFLICT (account_id, image_id) DO NOTHING
        """)
        print('新代码插入id',insert_sql) # 不需要担心有重复的。表里面有唯一索引。会跳过。
        # 假设 processed_items 是 [{'account_id':..., 'image_id':..., …}, …]
        with self.db_engine192.begin() as conn:
            conn.execute(insert_sql, processed_items)

    def save_homedepot_projects(self, items):
        """批量保存数据到数据库。"""
        table_name = "homedepot_projects_items"

        # 提取 image_title 和 image_size_info
        processed_items = []
        for item in items:
            image_title = item.get('title', '')
            image_size_info = json.dumps(item.get('sizes', {}))
            processed_item = {
                'account_id': item['account_id'],
                'image_id': item['image_id'],
                'state': item['state'],
                'created_at': item['created_at'],
                'image_title': image_title,
                'image_size_info': image_size_info
            }
            processed_items.append(processed_item)

        # 定义DataFrame的列
        columns = ['account_id', 'image_id', 'state', 'created_at', 'image_title', 'image_size_info']
        df = pd.DataFrame(processed_items, columns=columns)

        # 使用with语句管理数据库连接
        with self.db_engine192.connect() as connection:
            df.to_sql(
                name=table_name,
                con=connection,
                if_exists='append',
                index=False
            )



    def get_account_id(self, item_id):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_summary_wj"
            query = text(f"SELECT account_id, id FROM {table_name} WHERE id = :item_id")
            result = connection.execute(query, {"item_id": item_id})
            df_status = pd.DataFrame(result.fetchall())
            df_status.columns = result.keys()
            try:
                accounts = df_status.account_id.iloc[0]
            except IndexError:
                accounts = None  # 或者处理不存在的情况
            return accounts

    def update_id_to_3(self,account_id):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_summary_wj"
            success_id = tuple(account_id)
            sql_update = text(f"UPDATE {table_name} SET state = 3 WHERE account_id IN :success_id")
            result = connection.execute(sql_update, {"success_id": success_id})
            print('成功更新为3')
            connection.close()

    def update_all_states_to_1(self,state=1,item_id=None):
        try:
            with self.db_engine192.begin() as connection:  # 使用 begin() 自动管理事务
                table_name = "stock_image_summary_wj"
                if state==3:
                    sql_update = text(f"UPDATE {table_name} SET state = {state} where id={item_id}")
                else:
                    sql_update = text(f"UPDATE {table_name} SET state = {state}")
                print(sql_update)
                result = connection.execute(sql_update)
                print(f'成功更新所有状态为1，受影响行数：{result.rowcount}')

                # 显式提交事务（虽然 begin() 已经自动提交）
                connection.commit()
        except Exception as e:
            print(f'更新状态失败：{e}')
            # 回滚事务
            if 'connection' in locals():
                connection.rollback()


    def save_account(self,items):
        """批量保存数据到数据库。"""
        table_name = "stock_image_summary_wj"

        # 定义DataFrame的列
        columns = ['account_id', 'account_secret', 'year_month', 'spider_date','state','created_time']
        df = pd.DataFrame(items, columns=columns)

        # 使用with语句管理数据库连接
        with self.db_engine192.connect() as connection:
            df.to_sql(
                name=table_name,
                con=connection,
                if_exists='append',
                index=False
            )
        print("保存成功！")


    def delet_datails(self, image_id_list):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_detail_wj"

            # 使用 SQLAlchemy 的 text 函数来创建 SQL 语句
            query = text(f"SELECT image_id FROM {table_name} WHERE account_id = 'zhouweiqing@yswg.com.cn';")

            # 使用 connection.execute() 来执行查询
            result = connection.execute(query).fetchall()

            # 获取表中的 image_id 列表
            db_image_ids = [row[0] for row in result]

            # 找出不在 image_id_list 中的 image_id
            non_existent_image_ids = set(db_image_ids) - set(image_id_list)

            # 删除不在 image_id_list 中的记录
            for image_id in non_existent_image_ids:
                delete_query = text(
                    f"DELETE FROM {table_name} WHERE account_id = 'zhouweiqing@yswg.com.cn' AND image_id = '{image_id}';")
                connection.execute(delete_query)

            # 提交更改
            connection.commit()


    def get_datails_image_id(self, account_id):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_detail_wj"
            sql_query = text(f"SELECT image_id FROM {table_name} WHERE account_id = :account_id and created_time  < '2024-09-02 00:00:00'")
            result = connection.execute(sql_query, {"account_id": account_id})
            image_id_list = [int(row[0]) for row in result.fetchall()]
            # 提交更改
            # connection.commit()
            return image_id_list



    # 1111111111111
    def save_stock_detail(self, item):
        """批量保存数据到数据库。"""
        table_name = "stock_image_detail_wj"

        # 将item包装成列表
        items_list = [item]

        # 定义DataFrame的列
        columns = ['account_id', 'image_id', 'image_size_info', 'image_title', 'image_type', 'image_url','state', 'created_time']
        df = pd.DataFrame(items_list, columns=columns)

        with self.db_engine192.connect() as connection:
            df.to_sql(
                name=table_name,
                con=connection,
                if_exists='append',
                index=False
            )
        # print("保存成功！")


    def get_pic_urls_limit1(self, account_id):
        pic_data_list = []  # 创建一个空列表来存储结果
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_detail_wj"
            query = text(
                f"""select image_url, image_id, image_title from {table_name} where account_id = :account_id and state = 1 limit 1""")

            try:
                result = connection.execute(query, {'account_id': account_id})
                for row in result:  # 遍历所有的结果行
                    if row is not None:
                        # 将 RowProxy 转换为标准的字典
                        row_dict = dict(zip(result.keys(), row))  # 使用 keys 和 fetchone 的结果创建字典

                        # 直接构建所需格式的字符串
                        pic_datas = f"{row_dict['image_url']}||{row_dict['image_id']}||{row_dict['image_title']}"
                        pic_data_list.append(pic_datas)  # 添加到列表中

                if not pic_data_list:
                    # print("No data found for the given account_id")
                    return False
                else:
                    return pic_data_list  # 返回列表
            except Exception as e:
                print(f"An error occurred: {e}")
                return False


    def get_pic_urls(self, account_id):
        pic_data_list = []  # 创建一个空列表来存储结果
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_detail_wj"
            query = text(
                f"""select image_url, image_id, image_title from {table_name} where account_id = :account_id and state = 1""")

            try:
                result = connection.execute(query, {'account_id': account_id})
                for row in result:  # 遍历所有的结果行
                    if row is not None:
                        # 将 RowProxy 转换为标准的字典
                        row_dict = dict(zip(result.keys(), row))  # 使用 keys 和 fetchone 的结果创建字典

                        # 直接构建所需格式的字符串
                        pic_datas = f"{row_dict['image_url']}||{row_dict['image_id']}||{row_dict['image_title']}"
                        pic_data_list.append(pic_datas)  # 添加到列表中

                if not pic_data_list:
                    # print("No data found for the given account_id")
                    return False
                else:
                    return pic_data_list  # 返回列表
            except Exception as e:
                print(f"An error occurred: {e}")
                return False


    def get_stock_images_id2(self, account_id):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_id_wj"
            # 特定的 image_id 列表
            specific_image_ids = [
'1025406430',
'782084149',
'2340663257',
'2444918601',
'2481076155',
'2534369399',
'2522128969',
'2522144147',
'2482077119',
'2475085855',
'2560247125',
'1115348984',
'2555951185',
'1644852415',
'1644852424',
'258700904',
'2540342353',
'2555951245',
'2529955899',
'1309059847',
'1899316957',
'2416180707',
'1978653428',
'2520112131',
'1447499252',
'2335787565',
'1780440524',
'2316295613',
'2463106909',
'2527382733',
'2548693637',
'2460743889',
'2489123001',
'2527399543',
'2456315025',
'2469939069',
'2305915213',
'1660111006',
'2218802639',
'453729808',
'2295540279',
'2323950095',
'2323950087',
'2057817146',
'2541104423',
'231076948',
'2196541827',
'2407612765',
'2521017693',
'2554778219',
'2523427909',
'2520799267',
'2533854931',
'2498052331',
'2521798533',
'2471652945',
'2445858817',
'2449783031',
'1735869230',
'1106587370',
'2393397957',
'2527382699',
'2348771553',
'1822384931',
'2564084221'
]
            # specific_image_ids = ['2509630613', '2568241787', '2568242327', '2568242443', '2568242799', '2568242949']
            # 修改查询语句以匹配你的数据表名称、列名称，并加入 image_id 条件
            query = text(f"""SELECT image_id,id,image_title,image_size_info FROM {table_name} 
                             WHERE account_id = :account_id 
                             AND image_id IN :image_ids""")
            print(query)
            result = connection.execute(query, {'account_id': account_id, 'image_ids': tuple(specific_image_ids)})
            try:
                df_status = pd.DataFrame(result.fetchall())
                df_status.columns = result.keys()

                df_status['id'] = df_status['id'].astype(str)
                image_id_id_pairs = list(
                    df_status['image_id'].astype(str) + '||-||' + df_status['id'] + '||-||' + df_status[
                        'image_title'] + '||-||' + df_status['image_size_info'])
                print(f'账号：{account_id}需爬取{len(image_id_id_pairs)}张')
                return image_id_id_pairs
            except Exception as e:
                print(e)
                return False

    def img_size_is_1(self, account_id, image_ids):
        # 确保image_ids列表非空
        if not image_ids:
            print("No image IDs provided.")
            return False

        with self.db_engine192.connect() as connection:
            table_name = "stock_image_id_wj"
            query = text(f"""SELECT image_id, id, image_title, image_size_info  FROM {table_name} WHERE account_id = :account_id AND image_id IN :image_ids""")
            try:
                result = connection.execute(query, {'account_id': account_id, 'image_ids': tuple(image_ids)})
                df_status = pd.DataFrame(result.fetchall())
                df_status.columns = result.keys()
                df_status['id'] = df_status['id'].astype(str)
                image_id_id_pairs = list(
                    df_status['image_id'] + '||-||' + df_status['id'] + '||-||' + df_status['image_title'] + '||-||' +
                    df_status['image_size_info'])
                print(f'账号：{account_id}需爬取{len(image_id_id_pairs)}张')
                return image_id_id_pairs
            except Exception as e:
                print(e)
                return False

    def get_stock_images_id(self,account_id):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_id_wj"
            # 修改查询语句以匹配你的数据表名称和列名称
            query = text(f""" SELECT image_id,id,image_title,image_size_info FROM {table_name} where account_id = :account_id and state = 1""")

            print(query)
            result = connection.execute(query, {'account_id': account_id})
            try:
                df_status = pd.DataFrame(result.fetchall())
                df_status.columns = result.keys()


                df_status['id'] = df_status['id'].astype(str)
                image_id_id_pairs = list(df_status['image_id'] + '||-||' + df_status['id'] + '||-||' + df_status['image_title'] + '||-||' + df_status['image_size_info'])
                print(f'账号：{account_id}需爬取{len(image_id_id_pairs)}张')
                connection.close()
                return image_id_id_pairs
            except Exception as e:
                print(e)
                return False

    def get_kong_images_id(self, account_id):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_detail_wj"
            # 使用子查询来过滤掉已经有 image_size_info 的 image_id
            query = text(
                f"""SELECT image_id, image_type, image_url 
                    FROM {table_name} 
                    WHERE account_id = :account_id 
                    AND image_id NOT IN (
                        SELECT image_id 
                        FROM {table_name} 
                        WHERE account_id = :account_id 
                        AND image_size_info != '{{}}'
                    )
                    AND image_size_info = '{{}}'"""
            )
            print(query)
            result = connection.execute(query, {'account_id': account_id})
            df_status = pd.DataFrame(result.fetchall(), columns=result.keys())
            if df_status.empty:
                return []
            data_list = list(df_status['image_id'] + '||' + df_status['image_type'] + '||' + df_status['image_url'])
            connection.close()
            return data_list

    def get_stock_image_detail(self, account_id):
        with self.mysql_selection.connect() as connection:
            table_name = "stock_image_detail"
            query = text(
                f"""SELECT account_id, image_id, image_size_info, image_title, image_type, image_url, created_time FROM {table_name} WHERE account_id = :account_id""")
            print(query)
            result = connection.execute(query, {'account_id': account_id})
            df_status = pd.DataFrame(result.fetchall())
            df_status.columns = result.keys()

            # 将 Timestamp 转换为字符串格式
            df_status['created_time'] = df_status['created_time'].dt.strftime('%Y-%m-%d %H:%M:%S')

            # 拼接字符串
            detail_datas = list(
                df_status['account_id'] + '||-||' +
                df_status['image_id'] + '||-||' +
                df_status['image_size_info'] + '||-||' +
                df_status['image_title'] + '||-||' +
                df_status['image_type'] + '||-||' +
                df_status['image_url'] + '||-||' +
                df_status['created_time']
            )
            print(f'账号：{account_id} 一共 {len(detail_datas)} 条数据')
            return detail_datas

    def save_stock_detail_move(self, data_list):
        table_name = "stock_image_detail_wj"

        # 定义DataFrame的列
        columns = ['account_id', 'image_id', 'image_size_info', 'image_title', 'image_type', 'image_url',
                   'created_time']
        df = pd.DataFrame(data_list, columns=columns)

        with self.db_engine192.connect() as connection:
            df.to_sql(
                name=table_name,
                con=connection,
                if_exists='append',
                index=False
            )
        print("保存成功！")

    # 11111111111
    def update_image_id_to_3(self, item_id):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_id_wj"
            trans = connection.begin()
            sql_update = text(f"UPDATE {table_name} SET state = 3 WHERE id = :item_id")
            result = connection.execute(sql_update, {"item_id": item_id})
            trans.commit()

    def update_url_state_to_3(self,image_id):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_detail_wj"
            trans = connection.begin()
            sql_update = text(f"UPDATE {table_name} SET state = 3 WHERE image_id = :image_id and state = 1")
            result = connection.execute(sql_update, {"image_id": image_id})
            trans.commit()

    # 11111111111
    def update_image_id_to_4(self, item_id):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_id_wj"
            trans = connection.begin()
            sql_update = text(f"UPDATE {table_name} SET state = 4 WHERE id = :item_id")
            result = connection.execute(sql_update, {"item_id": item_id})
            connection.close()
            trans.commit()

    def save_stock_cookie(self,item):
        table_name = "stock_cookie_wj"
        # 将item包装成列表
        items_list = [item]
        # 定义DataFrame的列
        columns = ['account_id', 'cookie', 'state', 'created_at']
        df = pd.DataFrame(items_list, columns=columns)

        with self.db_engine192.connect() as connection:
            df.to_sql(
                name=table_name,
                con=connection,
                if_exists='append',
                index=False
            )
        print("保存成功！")

    def updata_ck_state(self,ck_id):
        with self.db_engine192.connect() as connection:
            table_name = "stock_cookie_wj"
            # 使用参数化查询防止SQL注入
            query = text(
                f"""UPDATE {table_name} SET state = :new_state WHERE id = :ck_id;""")

            try:
                # 执行更新语句
                result = connection.execute(query, {'new_state': 3, 'ck_id': ck_id})
                # 提交事务以确保更改被保存到数据库中
                connection.commit()

                # 检查是否有行受到影响
                if result.rowcount > 0:
                    print('修改cookie状态为3')
                    return True  # 更新成功

                else:
                    return False  # 没有找到匹配项或没有更新任何行
            except Exception as e:
                # print(f"An error occurred: {e}")
                return False


    def get_stock_cookie(self, account):
        with self.db_engine192.connect() as connection:
            table_name = "stock_cookie_wj"
            # 使用参数化查询
            query = text(
                f"""SELECT id, cookie, state FROM {table_name} WHERE account_id = :account_id AND state = :state LIMIT 1;""")
            result = connection.execute(query, {'account_id': account, 'state': 1}).mappings().first()

            if result is not None:
                # 通过键名访问字典中的元素
                cookie_id_state = f"{result['id']}||-||{result['cookie']}||-||{result['state']}"
                return cookie_id_state
            else:
                return None  # 没有找到匹配项时返回None

    def get_stock_cookie_list(self, account):
        with self.db_engine192.connect() as connection:
            table_name = "stock_cookie_wj"
            # 使用参数化查询
            query = text(f"""SELECT cookie FROM {table_name} WHERE account_id = :account_id AND state = :state ; """)
            result = connection.execute(query, {'account_id': account, 'state': 1})
            df_status = pd.DataFrame(result.fetchall())
            df_status.columns = result.keys()
            cookie_list = df_status['cookie'].tolist() if 'cookie' in df_status.columns else []
            return cookie_list

    def get_cookie_account(self,item_id):
        # try:
            with self.db_engine192.connect() as connection:
                table_name = "stock_image_summary_wj"
                # 修改查询语句以匹配你的数据表名称和列名称
                query = text(f"""SELECT account_id,account_secret FROM {table_name} where id = :item_id and state= :state_int;""")
                print(query)
                result = connection.execute(query, {'item_id': item_id,'state_int':1})
                print(result)
                df_status = pd.DataFrame(result.fetchall())
                if len(df_status)>0:
                    df_status.columns = result.keys()
                    account_id = df_status.account_id.iloc[0]
                    account_secret = df_status.account_secret.iloc[0]
                    account_list = [account_id, account_secret]
                    print(account_list,'232323====32')
                    # print(111111111111)
                    connection.close()
                    return account_list
                else:
                    return None
        # except Exception as e:
        #     print(111111111)

    def get_stock_test_id(self,username):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_id_wj"
            # 修改查询语句以匹配你的数据表名称和列名称
            query = text(f"""SELECT image_id FROM {table_name} WHERE account_id = :username LIMIT 1;""")
            result = connection.execute(query, {'username': username})
            df_status = pd.DataFrame(result.fetchall())
            df_status.columns = result.keys()
            image_id = df_status.image_id.iloc[0]
            connection.close()
            return image_id

    def upload_data(self, account_id, image_id, upload_time, err_msg):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_detail_wj"
            # 强制将 image_id 转换为字符串类型
            image_id = str(image_id)
            err_msg_json = json.dumps(err_msg)
            sql_update = text(
                f"UPDATE {table_name} SET upload_time = :upload_time, err_msg = :err_msg WHERE account_id = :account_id AND image_id = :image_id AND created_time  < '2024-09-02 00:00:00'")
            result = connection.execute(sql_update, {
                "upload_time": upload_time,
                "err_msg": err_msg_json,
                "account_id": account_id,
                "image_id": image_id
            })

    def upload_success_data(self, account_id, image_id, upload_time):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_detail_wj"
            # 强制将 image_id 转换为字符串类型
            image_id = str(image_id)
            sql_update = text(
                f"UPDATE {table_name} SET upload_time = :upload_time WHERE account_id = :account_id AND image_id = :image_id AND created_time  < '2024-09-02 00:00:00'")
            result = connection.execute(sql_update, {
                "upload_time": upload_time,
                "account_id": account_id,
                "image_id": image_id
            })



    def get_all_image_id(self):
        with self.db_engine192.connect() as connection:
            table_name = "stock_image_detail_wj"
            sql_query = f"SELECT image_id FROM {table_name} "
            df_status = pd.read_sql(sql_query, con=connection)
            image_id = list(df_status['image_id'].astype(str))

            connection.close()
            return image_id






if __name__ == '__main__':
    ConnectSpider().get_cookie_account(1)

