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
})
defget_all_image_id(self):
defget_all_image_id(self):
withself.db_engine192.connect()asconnection:
foriinrange(5):
try:
table_name="stock_image_detail_wj"
table_name="stock_image_detail_wj"
sql_query=f"SELECT image_id FROM {table_name} "
sql_query=f"SELECT image_id FROM {table_name} "
df_status=pd.read_sql(sql_query,con=connection)
df_status=self.db_engine192.read_sql(sql_query)
image_id=list(df_status['image_id'].astype(str))
image_id=list(df_status['image_id'].astype(str))
connection.close()
returnimage_id
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']