|
@@ -17,6 +17,7 @@ from dateutil.parser import parse
|
|
|
import pymysql
|
|
|
from typing import List, Literal
|
|
|
from random import shuffle
|
|
|
+from ..settings import MYSQL_AUTH_CONF, MYSQL_DATA_CONF
|
|
|
|
|
|
class SpApiRequest:
|
|
|
|
|
@@ -29,26 +30,13 @@ class SpApiRequest:
|
|
|
|
|
|
@classmethod
|
|
|
def mysql_connect_auth(cls):
|
|
|
- conn = pymysql.connect(user="admin",
|
|
|
- password="NSYbBSPbkGQUbOSNOeyy",
|
|
|
- host="retail-data.cnrgrbcygoap.us-east-1.rds.amazonaws.com",
|
|
|
- database="ansjer_dvadmin",
|
|
|
- port=3306)
|
|
|
+ conn = pymysql.connect(**MYSQL_AUTH_CONF)
|
|
|
|
|
|
return conn
|
|
|
|
|
|
@classmethod
|
|
|
def mysql_connect_auth_lst(cls):
|
|
|
- conn = pymysql.connect(user="root",
|
|
|
- password="sandbox",
|
|
|
- host="192.168.1.225",
|
|
|
- database="asj_ads",
|
|
|
- port=3306)
|
|
|
- # conn = pymysql.connect(user="huangyifan",
|
|
|
- # password="123456",
|
|
|
- # host="127.0.0.1",
|
|
|
- # database="amz_sp_api",
|
|
|
- # port=3306)
|
|
|
+ conn = pymysql.connect(**MYSQL_DATA_CONF)
|
|
|
return conn
|
|
|
|
|
|
@classmethod
|
|
@@ -356,8 +344,8 @@ class SpApiRequest:
|
|
|
# merged_df['temp_columns'] = merged_df.apply(lambda x: self.get_listing_info(x['seller-sku'],seller_id),axis=1)
|
|
|
# merged_df[['image_link','title']] = merged_df['temp_columns'].str.split("-----",expand=True)
|
|
|
merged_df['image_link'] = ''
|
|
|
- merged_df['title'] = ''
|
|
|
- merged_df['modifier'] = refresh_token
|
|
|
+ merged_df['title'] = refresh_token
|
|
|
+ merged_df['modifier'] = ''
|
|
|
|
|
|
|
|
|
merged_df.fillna('',inplace=True)
|
|
@@ -768,14 +756,14 @@ class SpApiRequest:
|
|
|
cursor = conn.cursor()
|
|
|
# print(list(conn.query("select * from amz_sp_api.orderReport")))
|
|
|
sql = f"""
|
|
|
- insert into asj_ads.orderReport_(`amazon-order-id`, `merchant-order-id`, `purchase-date`, `last-updated-date`, `order-status`,
|
|
|
- `fulfillment-channel`, `sales-channel`, `order-channel`, `ship-service-level`,
|
|
|
- `product-name`,
|
|
|
- `sku`, `asin`, `item-status`, `quantity`, `currency`, `item-price`, `item-tax`,
|
|
|
- `shipping-price`,
|
|
|
- `shipping-tax`, `gift-wrap-price`, `gift-wrap-tax`, `item-promotion-discount`,
|
|
|
- `ship-promotion-discount`, `ship-city`, `ship-state`, `ship-postal-code`, `ship-country`,
|
|
|
- `promotion-ids`, `is-business-order`, `purchase-order-number`, `price-designation`,
|
|
|
+ insert into asj_ads.orderReport_(`amazon_order_id`, `merchant_order_id`, `purchase_date`, `last_updated_date`, `order_status`,
|
|
|
+ `fulfillment_channel`, `sales_channel`, `order_channel`, `ship_service_level`,
|
|
|
+ `product_name`,
|
|
|
+ `sku`, `asin`, `item_status`, `quantity`, `currency`, `item_price`, `item_tax`,
|
|
|
+ `shipping_price`,
|
|
|
+ `shipping_tax`, `gift_wrap_price`, `gift_wrap_tax`, `item_promotion_discount`,
|
|
|
+ `ship_promotion_discount`, `ship_city`, `ship_state`, `ship_postal_code`, `ship_country`,
|
|
|
+ `promotion_ids`, `is_business_order`, `purchase_order_number`, `price_designation`,
|
|
|
`ReportDate`,
|
|
|
`timezone`, `seller_id`, `country_code`,`insert_time`)
|
|
|
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,%s,%s,%s,%s,%s,%s,%s)
|
|
@@ -803,8 +791,9 @@ class SpApiRequest:
|
|
|
def listing_infoTable(cls):
|
|
|
conn = SpApiRequest.mysql_connect_auth_lst()
|
|
|
cursor = conn.cursor()
|
|
|
- cursor.execute(f"""select seller_id,country_code,asin,modifier from asj_ads.seller_listings where modifier is not null and (seller_id,country_code,asin) not in (select seller_id,country_code,asin from asj_ads.Goods where update_time>='{datetime.today().date()}') group by seller_id,modifier,country_code,asin""")
|
|
|
+ cursor.execute(f"""select seller_id,country_code,asin,title from asj_ads.seller_listings where title is not null and title <>'' and (seller_id,country_code,asin) not in (select seller_id,country_code,asin from asj_ads.Goods where update_time>='{datetime.today().date()}') group by seller_id,title,country_code,asin""")
|
|
|
query_ = cursor.fetchall()
|
|
|
+ # print(query_)
|
|
|
col_name = [i[0] for i in cursor.description]
|
|
|
df_datatable = pd.DataFrame(query_, columns=col_name)
|
|
|
count=0
|
|
@@ -813,7 +802,7 @@ class SpApiRequest:
|
|
|
while count<len(df_datatable):
|
|
|
df = df_datatable.iloc[count:count+distance,:]
|
|
|
count = count+distance
|
|
|
- df['detail_info'] = df.apply(lambda x: cls.get_listing_info01(x['modifier'],x['country_code'],x['asin'],x['seller_id']),axis=1)
|
|
|
+ df['detail_info'] = df.apply(lambda x: cls.get_listing_info01(x['title'],x['country_code'],x['asin'],x['seller_id']),axis=1)
|
|
|
detail_info_k = df['detail_info'].map(lambda x: list(x.keys())).to_numpy().tolist()
|
|
|
detail_info_v = df['detail_info'].map(lambda x: list(x.values())).to_numpy().tolist()
|
|
|
|
|
@@ -846,6 +835,7 @@ class SpApiRequest:
|
|
|
|
|
|
@staticmethod
|
|
|
def get_listing_info01(refresh_token, countryCode, asin, seller_id):
|
|
|
+ # print(refresh_token)
|
|
|
aws_credentials = {
|
|
|
'refresh_token': refresh_token,
|
|
|
'lwa_app_id': 'amzn1.application-oa2-client.1f9d3d4747e14b22b4b598e54e6b922e', # 卖家中心里面开发者资料LWA凭证
|
|
@@ -889,6 +879,7 @@ class SpApiRequest:
|
|
|
try:
|
|
|
variations = cate_item.get_catalog_item(asin=asin, **{"includedData": ['variations']})
|
|
|
var_info = variations.payload
|
|
|
+ # print(variations)
|
|
|
IsParent = 'Y'
|
|
|
parent_asin = ''
|
|
|
if len(var_info['variations']) > 0:
|
|
@@ -1108,7 +1099,7 @@ class SpApiRequest:
|
|
|
if __name__ == '__main__':
|
|
|
for days in range(35,45):
|
|
|
SpApiRequest.get_allShops("GET_SALES_AND_TRAFFIC_REPORT",days=-days,**{"level":"SKU"})
|
|
|
- SpApiRequest.listing_infoTable()
|
|
|
+ # SpApiRequest.listing_infoTable()
|
|
|
# rel = SpApiRequest.get_catelog(account_name='ANLAPUS_US',country=Marketplaces.US,asin='B0BVXB4KT9')
|
|
|
# print(rel)
|
|
|
|