|
@@ -150,8 +150,10 @@ class SpApiRequest:
|
|
|
decom_df = self.decompression(reportid)
|
|
|
print("连接数据库")
|
|
|
conn = self.mysql_connect()
|
|
|
+ print("连接成功")
|
|
|
cursor = conn.cursor()
|
|
|
- bondary_date = (datetime.today()).strftime("%Y-%m-%d") #+ timedelta(days=-28)
|
|
|
+ timezone = pytz.timezone(self.timezone)
|
|
|
+ bondary_date = (datetime.now(tz=timezone)).strftime("%Y-%m-%d") #+ timedelta(days=-28)
|
|
|
cursor.execute(f"""select * from amz_sp_api.productInfo where (mainImageUrl is not null and mainImageUrl not in ('', ' ')) and
|
|
|
(`seller-sku` not in ('',' ') and `seller-sku` is not null) and
|
|
|
`updateTime`>='{bondary_date}'""") #`seller-sku`,`updateTime`,`mainImageUrl`
|
|
@@ -163,9 +165,10 @@ class SpApiRequest:
|
|
|
df = pd.DataFrame(query_rel,columns=col)
|
|
|
listingid = df['listing-id'].to_numpy().tolist()
|
|
|
decom_df = decom_df.query("`listing-id` not in @listingid")
|
|
|
+ print("数据条数: ",len(decom_df))
|
|
|
# print(f"delete * from amz_sp_api.productInfo where `listing-id` not in {tuple(listingid)}")
|
|
|
- cursor.execute(f"delete from amz_sp_api.productInfo where `listing-id` not in {tuple(listingid)}")
|
|
|
- conn.commit()
|
|
|
+
|
|
|
+ # conn.commit()
|
|
|
|
|
|
if len(decom_df)==0:
|
|
|
return "Done"
|
|
@@ -187,16 +190,35 @@ class SpApiRequest:
|
|
|
values (%s,%s,%s,%s,%s,%s,%s, %s,%s,%s,%s,%s,%s,%s, %s,%s,%s,%s,%s,%s,%s, %s,%s,%s,%s,%s,%s,%s,%s)
|
|
|
""" #ok
|
|
|
# print(sql)
|
|
|
+ conn = self.mysql_connect()
|
|
|
+ cursor = conn.cursor()
|
|
|
try:
|
|
|
conn.begin()
|
|
|
cursor.executemany(sql, list_df)
|
|
|
conn.commit()
|
|
|
print("插入中...")
|
|
|
+ insert_listingid = df_insert['listing-id'].to_numpy().tolist()
|
|
|
+ cursor.execute(f"delete from amz_sp_api.productInfo where `listing-id` not in {tuple(insert_listingid)} and `updateTime`<'{bondary_date}'")
|
|
|
+ conn.commit()
|
|
|
rowcount += 200
|
|
|
except Exception as e:
|
|
|
conn.rollback()
|
|
|
print(e)
|
|
|
- break
|
|
|
+ try:
|
|
|
+ conn = self.mysql_connect()
|
|
|
+ cursor = conn.cursor()
|
|
|
+ conn.begin()
|
|
|
+ cursor.executemany(sql, list_df)
|
|
|
+ conn.commit()
|
|
|
+ insert_listingid = df_insert['listing-id'].to_numpy().tolist()
|
|
|
+ cursor.execute(f"delete from amz_sp_api.productInfo where `listing-id` not in {tuple(insert_listingid)} and `updateTime`<'{bondary_date}'")
|
|
|
+ conn.commit()
|
|
|
+ except Exception as e:
|
|
|
+ conn.rollback()
|
|
|
+ print(e)
|
|
|
+ break
|
|
|
+ # break
|
|
|
+ conn.close()
|
|
|
print("全部完成")
|
|
|
end =time.time()
|
|
|
print("duration:",end-start)
|
|
@@ -209,7 +231,7 @@ class SpApiRequest:
|
|
|
img = r1.payload.get("summaries")[0].get("mainImage")
|
|
|
img_url = None if img is None else img.get("link")
|
|
|
except Exception as e:
|
|
|
- print(e)
|
|
|
+ print("获取图片url过程错误重试, 错误message: ",e)
|
|
|
time.sleep(3)
|
|
|
r1 = listingClient.get_listings_item(sellerId=self.shopInfo['advertiser_id'], sku=sku)
|
|
|
img = r1.payload.get("summaries")[0].get("mainImage")
|
|
@@ -422,7 +444,7 @@ if __name__ == '__main__':
|
|
|
'role_arn': 'arn:aws:iam::070880041373:role/Amazon_SP_API_ROLE'
|
|
|
}
|
|
|
sp_ = SpApiRequest(aws_credentials,Marketplaces.US,'3006125408623189')
|
|
|
- sp_.GET_MERCHANT_LISTINGS_ALL_DATA()
|
|
|
+ sp_.GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL()
|
|
|
"""
|
|
|
create database amz_sp_api;
|
|
|
"""
|