sql_update=f"UPDATE {table_name} SET state = 3 WHERE id = {item_id}"
connection.execute(sql_update)
break
exceptExceptionase:
time.sleep(30)
print(f'update_image_id_to_3 报错:{e}')
# 回滚事务
defupdate_image_id_to_4(self,item_id):
foriinrange(5):
try:
withself.db_engine192.begin()asconnection:
table_name="stock_image_id_wj"
sql_update=f"UPDATE {table_name} SET state = 4 WHERE id = {item_id}"
connection.execute(sql_update)
break
exceptExceptionase:
time.sleep(30)
print(f'update_image_id_to_4 报错:{e}')
defget_cookie_account(self,item_id):
foriinrange(5):
try:
table_name="stock_image_summary_wj"
# 修改查询语句以匹配你的数据表名称和列名称
query=f"""SELECT account_id,account_secret FROM {table_name} where id = {item_id} and state= 1;"""
print(query)
df_status=self.db_engine192.read_sql(query)
iflen(df_status)>0:
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')
returnaccount_list
else:
returnNone
exceptExceptionase:
time.sleep(30)
print(f'get_cookie_account 报错:{e}')
defget_all_image_id(self):
foriinrange(5):
try:
table_name="stock_image_detail_wj"
sql_query=f"SELECT image_id FROM {table_name} "
df_status=self.db_engine192.read_sql(sql_query)
image_id=list(df_status['image_id'].astype(str))
returnimage_id
exceptExceptionase:
time.sleep(30)
print(f'get_all_image_id 报错:{e}')
defupdate_url_state_to_3(self,image_id):
foriinrange(5):
try:
withself.db_engine192.begin()asconnection:
table_name="stock_image_detail_wj"
sql_update=f"UPDATE {table_name} SET state = 3 WHERE image_id ='{image_id}' and state = 1"
connection.execute(sql_update)
break
exceptExceptionase:
time.sleep(30)
print(f'update_url_state_to_3 报错:{e}')
defget_pic_urls(self,account_id):
pic_data_list=[]# 创建一个空列表来存储结果
table_name="stock_image_detail_wj"
query=f"""select image_url, image_id, image_title from {table_name} where account_id = '{account_id}' and state = 1"""
try:
result_df=self.db_engine192.read_sql(query)
# print(result_df)
result_list=result_df.values.tolist()
forrowinresult_list:# 遍历所有的结果行
ifrowisnotNone:
# 直接构建所需格式的字符串
pic_datas=f"{row[0]}||{row[1]}||{row[2]}"
pic_data_list.append(pic_datas)# 添加到列表中
"""
['https://download.shutterstock.com/gatekeeper/W3siZCI6ICJzaHV0dGVyc3RvY2stbWVkaWEiLCAiayI6ICJwaG90by8yNDY2MDI5NDI1L2h1Z2UuanBnIiwgImRjIjogImlkbF8xMjMiLCAiZSI6IDE3NDYwMTIzNDQsICJtIjogMX0sICJBb0dOUzZDMXNiVU1XczgxMFN5YVBsUEJrakEiXQ==/shutterstock_2466029425.jpg||2466029425||Beautiful smiling model in sunglasses. Female dressed in summer hipster white T-shirt and jeans. Posing near white wall in the street. Funny and positive woman having fun outdoors, in sunglasses']