# -*- coding: utf-8 -*- import os from typing import Optional, Dict, Any, List from public_function.asyn_mysql import AsyncMySQL class DealAccount: def __init__(self, config_data: Dict[str, Any]): self.config_data = config_data self.db_pool: Optional[AsyncMySQL] = AsyncMySQL(self.config_data["advert_policy"]) async def add_account(self, params: List[Dict[str, Any]]): """新增账户""" await self.db_pool.initialize() result = await self.db_pool.insert_many(table="crawler_account_record_info", data=params) if result: return True return False async def delete_account(self, params: List[str]): """删除账户""" if len(params) == 1: condition = "account_id={}".format(params[0]) else: condition = f"account_id in ({','.join(params)})" await self.db_pool.initialize() result = await self.db_pool.delete(table="crawler_account_record_info", where_conditions=condition) if result: return True return False async def query_account_info(self, params: Dict[str, Any]): """查询具体账户信息""" sql_str = f"""select * from crawler_account_record_info where account_id='{params['account_id']}'""" await self.db_pool.initialize() result = await self.db_pool.fetch_all(sql_str, ) if result: return result return [] async def obtain_account_info(self, app_name, country, number=1): """获取指定个数账户信息""" sql_str = f"""select account_id,password from crawler_account_record_info where status=1 and app_name='{app_name}' and country='{country}' limit {number}""" await self.db_pool.initialize() result = await self.db_pool.fetch_all(sql_str, ) if result: return result return [] async def update_account_info(self, set_param: Dict[str, Any], params): """更新账户信息""" # params = {'name': '张三', 'age': 25} where_conditions = "account_id = %s" await self.db_pool.initialize() affected_rows = await self.db_pool.update(table='crawler_account_record_info', set_columns=set_param, where_conditions=where_conditions, params=params) if affected_rows: return True return False