|
@@ -165,7 +165,7 @@ class SpApiRequest:
|
|
df = pd.read_table(rp_table.payload.get("url"),encoding='Shift-JIS')
|
|
df = pd.read_table(rp_table.payload.get("url"),encoding='Shift-JIS')
|
|
print(df.columns)
|
|
print(df.columns)
|
|
return df
|
|
return df
|
|
- except:
|
|
|
|
|
|
+ except Exception as e:
|
|
print("==========!!!!!!!!")
|
|
print("==========!!!!!!!!")
|
|
try:
|
|
try:
|
|
df = pd.read_table(rp_table.payload.get("url"),encoding='iso-8859-1')
|
|
df = pd.read_table(rp_table.payload.get("url"),encoding='iso-8859-1')
|
|
@@ -1259,67 +1259,71 @@ class SpApiRequest:
|
|
pass
|
|
pass
|
|
|
|
|
|
def GET_SELLER_FEEDBACK_DATA(self,refresh_token,seller_id,days,**a_kw):
|
|
def GET_SELLER_FEEDBACK_DATA(self,refresh_token,seller_id,days,**a_kw):
|
|
- kwargs = a_kw
|
|
|
|
- country_code = str(self.marketplace)[-2:]
|
|
|
|
- if country_code == 'GB':
|
|
|
|
- country_code = "UK"
|
|
|
|
- insert_time = datetime.now()
|
|
|
|
- shopReportday = (datetime.now().date() + timedelta(days=days)).strftime("%Y-%m-%d")
|
|
|
|
- shopReportday_E = (datetime.now().date() + timedelta(days=days)).strftime("%Y-%m-%d")
|
|
|
|
- client = get_client(host='3.93.43.158', port=8123, username='root',
|
|
|
|
- password='6f0eyLuiVn3slzbGWpzI')
|
|
|
|
- tmp_df = client.query_df(
|
|
|
|
- """select * from ams.performance where seller_id='%s' and country_code='%s' and date='%s' and isFeedback=1""" % (
|
|
|
|
- seller_id, country_code, shopReportday))
|
|
|
|
- if len(tmp_df) > 0:
|
|
|
|
- print("数据已存在")
|
|
|
|
- return 'Done'
|
|
|
|
- print(shopReportday)
|
|
|
|
- para = {"reportType": ReportType.GET_SELLER_FEEDBACK_DATA,#GET_SELLER_FEEDBACK_DATA,# GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE |GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA
|
|
|
|
- "dataStartTime": shopReportday,
|
|
|
|
- "dataEndTime": shopReportday_E, "reportOptions":{"reportPeriod": "DAY"}}
|
|
|
|
try:
|
|
try:
|
|
- reportid = self.create_report(**para)
|
|
|
|
- decom_df = self.decompression(reportid)
|
|
|
|
- except:
|
|
|
|
- return pd.DataFrame()
|
|
|
|
- if len(decom_df) == 0:
|
|
|
|
|
|
+ kwargs = a_kw
|
|
|
|
+ country_code = str(self.marketplace)[-2:]
|
|
|
|
+ if country_code == 'GB':
|
|
|
|
+ country_code = "UK"
|
|
|
|
+ insert_time = datetime.now()
|
|
|
|
+ shopReportday = (datetime.now().date() + timedelta(days=days)).strftime("%Y-%m-%d")
|
|
|
|
+ shopReportday_E = (datetime.now().date() + timedelta(days=days)).strftime("%Y-%m-%d")
|
|
|
|
+ client = get_client(host='3.93.43.158', port=8123, username='root',
|
|
|
|
+ password='6f0eyLuiVn3slzbGWpzI')
|
|
|
|
+ tmp_df = client.query_df(
|
|
|
|
+ """select * from ams.performance where seller_id='%s' and country_code='%s' and date='%s' and isFeedback=1""" % (
|
|
|
|
+ seller_id, country_code, shopReportday))
|
|
|
|
+ if len(tmp_df) > 0:
|
|
|
|
+ print("数据已存在")
|
|
|
|
+ return 'Done'
|
|
|
|
+ print(shopReportday)
|
|
|
|
+ para = {"reportType": ReportType.GET_SELLER_FEEDBACK_DATA,#GET_SELLER_FEEDBACK_DATA,# GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE |GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA
|
|
|
|
+ "dataStartTime": shopReportday,
|
|
|
|
+ "dataEndTime": shopReportday_E, "reportOptions":{"reportPeriod": "DAY"}}
|
|
|
|
+ try:
|
|
|
|
+ reportid = self.create_report(**para)
|
|
|
|
+ decom_df = self.decompression(reportid)
|
|
|
|
+ except:
|
|
|
|
+ return pd.DataFrame()
|
|
|
|
+ if len(decom_df) == 0:
|
|
|
|
+ return reportid
|
|
|
|
+ decom_df[decom_df.select_dtypes(float).columns] = decom_df[decom_df.select_dtypes(float).columns].applymap(
|
|
|
|
+ lambda x: str(x) if not pd.isna(x) else '')
|
|
|
|
+ decom_df[decom_df.select_dtypes(int).columns] = decom_df[decom_df.select_dtypes(int).columns].applymap(
|
|
|
|
+ lambda x: str(x) if not pd.isna(x) else '')
|
|
|
|
+ decom_df[decom_df.select_dtypes(datetime).columns] = decom_df[
|
|
|
|
+ decom_df.select_dtypes(datetime).columns].applymap(lambda x: str(x) if not pd.isna(x) else '')
|
|
|
|
+ decom_df.fillna('', inplace=True)
|
|
|
|
+ # decom_df.to_csv('order.csv')
|
|
|
|
+ decom_df["ReportDate"] = parse(shopReportday)
|
|
|
|
+ # decom_df['timezone'] = decom_df["purchase-date"].map(lambda x: parse(x).tzname()).fillna(method='bfill')
|
|
|
|
+ decom_df['timezone'] = "UTC"
|
|
|
|
+ # print("==========================================================")
|
|
|
|
+ decom_df['seller_id'] = seller_id
|
|
|
|
+ decom_df['country_code'] = country_code
|
|
|
|
+ decom_df['insert_time'] = datetime.now()
|
|
|
|
+ df_feedback = decom_df.copy()
|
|
|
|
+ df_feedback[["date", "rating", "comment", "order_id"]] = df_feedback[["Date", "Rating", "Comments", "Order ID"]]
|
|
|
|
+ df_feedback['isFeedback'] = 1
|
|
|
|
+
|
|
|
|
+ df_feedback['date'] = df_feedback['date'].map(lambda x: pd.to_datetime(x).date())
|
|
|
|
+ df_feedback['seller_id'] = seller_id
|
|
|
|
+ df_feedback['country_code'] = country_code
|
|
|
|
+ # client = get_client(host='3.93.43.158', port=8123, username='root',
|
|
|
|
+ # password='6f0eyLuiVn3slzbGWpzI')
|
|
|
|
+ try:
|
|
|
|
+ client.insert_df(table='ams.performance', df=df_feedback[
|
|
|
|
+ ["date", "rating", "comment", "order_id", "isFeedback", 'seller_id', 'country_code','insert_time']],
|
|
|
|
+ column_names=["date", "rating", "comment", "order_id", "isFeedback", 'seller_id',
|
|
|
|
+ 'country_code','insert_time'])
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ client.close()
|
|
|
|
+ # print(decom_df.columns)
|
|
|
|
+ # print(decom_df)
|
|
return reportid
|
|
return reportid
|
|
- decom_df[decom_df.select_dtypes(float).columns] = decom_df[decom_df.select_dtypes(float).columns].applymap(
|
|
|
|
- lambda x: str(x) if not pd.isna(x) else '')
|
|
|
|
- decom_df[decom_df.select_dtypes(int).columns] = decom_df[decom_df.select_dtypes(int).columns].applymap(
|
|
|
|
- lambda x: str(x) if not pd.isna(x) else '')
|
|
|
|
- decom_df[decom_df.select_dtypes(datetime).columns] = decom_df[
|
|
|
|
- decom_df.select_dtypes(datetime).columns].applymap(lambda x: str(x) if not pd.isna(x) else '')
|
|
|
|
- decom_df.fillna('', inplace=True)
|
|
|
|
- # decom_df.to_csv('order.csv')
|
|
|
|
- decom_df["ReportDate"] = parse(shopReportday)
|
|
|
|
- # decom_df['timezone'] = decom_df["purchase-date"].map(lambda x: parse(x).tzname()).fillna(method='bfill')
|
|
|
|
- decom_df['timezone'] = "UTC"
|
|
|
|
- # print("==========================================================")
|
|
|
|
- decom_df['seller_id'] = seller_id
|
|
|
|
- decom_df['country_code'] = country_code
|
|
|
|
- decom_df['insert_time'] = datetime.now()
|
|
|
|
- df_feedback = decom_df.copy()
|
|
|
|
- df_feedback[["date", "rating", "comment", "order_id"]] = df_feedback[["Date", "Rating", "Comments", "Order ID"]]
|
|
|
|
- df_feedback['isFeedback'] = 1
|
|
|
|
-
|
|
|
|
- df_feedback['date'] = df_feedback['date'].map(lambda x: pd.to_datetime(x).date())
|
|
|
|
- df_feedback['seller_id'] = seller_id
|
|
|
|
- df_feedback['country_code'] = country_code
|
|
|
|
- # client = get_client(host='3.93.43.158', port=8123, username='root',
|
|
|
|
- # password='6f0eyLuiVn3slzbGWpzI')
|
|
|
|
- try:
|
|
|
|
- client.insert_df(table='ams.performance', df=df_feedback[
|
|
|
|
- ["date", "rating", "comment", "order_id", "isFeedback", 'seller_id', 'country_code','insert_time']],
|
|
|
|
- column_names=["date", "rating", "comment", "order_id", "isFeedback", 'seller_id',
|
|
|
|
- 'country_code','insert_time'])
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print(e)
|
|
print(e)
|
|
- client.close()
|
|
|
|
- # print(decom_df.columns)
|
|
|
|
- # print(decom_df)
|
|
|
|
- return reportid
|
|
|
|
|
|
+ return e
|
|
def GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA(self,refresh_token,seller_id,days,**a_kw):
|
|
def GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA(self,refresh_token,seller_id,days,**a_kw):
|
|
kwargs = a_kw
|
|
kwargs = a_kw
|
|
country_code = str(self.marketplace)[-2:]
|
|
country_code = str(self.marketplace)[-2:]
|
|
@@ -1613,8 +1617,8 @@ class SpApiRequest:
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
# for days in range(-17,-2):
|
|
# for days in range(-17,-2):
|
|
# SpApiRequest.get_allShops("GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE",days=days,**{})
|
|
# SpApiRequest.get_allShops("GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE",days=days,**{})
|
|
- for days in range(-5,-60,-1):
|
|
|
|
- SpApiRequest.get_allShops("GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA",days=days,**{})
|
|
|
|
|
|
+ for days in range(-40,-60,-1):
|
|
|
|
+ SpApiRequest.get_allShops("GET_SELLER_FEEDBACK_DATA",days=days,**{})
|
|
#
|
|
#
|
|
# SpApiRequest.listing_infoTable()
|
|
# SpApiRequest.listing_infoTable()
|
|
# rel = SpApiRequest.get_catelog(account_name='AM-ZOSI-US',country=Marketplaces.US,asin='B0B8CPHSL4')
|
|
# rel = SpApiRequest.get_catelog(account_name='AM-ZOSI-US',country=Marketplaces.US,asin='B0B8CPHSL4')
|