Эх сурвалжийг харах

Merge branch 'wengao' of ASJ_ADS/sync_amz_data into master

wengao 1 жил өмнө
parent
commit
b48d792f87

+ 2 - 2
sync_amz_data/public/amz_ad_client.py

@@ -294,9 +294,9 @@ class SPClient(BaseClient):
         return self._request(url_path,method="POST",body=body)
 
     def iter_bidrecommendationList(self, adGroupId, expressions):
-        for i in range(0,len(expressions), 10):
+        for i in range(0,len(expressions), 50):
             try:
-                info = self.get_bidrecommendationList(adGroupId, expressions[i:i+10])
+                info = self.get_bidrecommendationList(adGroupId, expressions[i:i+50])
                 out = info['recommendations']
                 for i in out:
                     i['adGroupId'] = adGroupId

+ 31 - 0
sync_amz_data/tasks/datainsert/SB/mysql_datainsert_sbcampaign.py

@@ -6,6 +6,33 @@ import pandas as pd
 import json
 
 
+pd.set_option('display.max_columns', None)
+# 显示所有行
+pd.set_option('display.max_rows', None)
+
+
+def convert_row(row):
+    l_d = None
+    l_o = None
+    l_h = None
+    if len(row['dyp']) > 0:
+        for i in row['dyp']:
+            a = json.loads(i)
+            if 'placement' in a:
+                if a['placement'] == "DETAIL_PAGE":
+                    l_d = a['percentage']
+                if a['placement'] == "OTHER":
+                    l_o = a['percentage']
+                if a['placement'] == "HOME":
+                    l_h = a['percentage']
+    return l_d, l_o, l_h
+
+def parse_dict_list(lst):
+    if lst == 999:
+        return []
+    else:
+        return [json.dumps(json_str) for json_str in lst]
+
 class RateLimitError(Exception):
     def __init__(self, retry_after: str = None):
         self.retry_after = retry_after
@@ -90,6 +117,10 @@ class SbCampaign:
         tem = pd.concat([old, df]).reset_index()
         tem.drop(columns='index', inplace=True)
         tem.columns = [i.replace(".", "_") for i in tem.columns]
+        tem.bidding_bidAdjustmentsByPlacement = tem.bidding_bidAdjustmentsByPlacement.fillna(999)
+        tem['dyp'] = tem.bidding_bidAdjustmentsByPlacement.apply(parse_dict_list)
+        tem[['detatil_page', 'other', 'home']] = tem.apply(convert_row, axis=1, result_type='expand')
+        tem.drop(columns='dyp', inplace=True)
         tem.rename(columns={
             'name': 'campaignName',
             'portfolioId': 'portfolio',

+ 48 - 0
sync_amz_data/tasks/datainsert/alldata_insert.py

@@ -18,77 +18,125 @@ from SB.mysql_datainsert_sb_keywordsbid_recommendations_v3 import SbkeywordsBidR
 from SB.mysql_datainsert_sbtarget_v3 import SbTargets
 from SB.mysql_datainsert_sbtargetbid_recommendations_v3 import SbtargetsBidRecommendations
 
+import time
+
+
+def protime(start_time):
+    end_time = time.time()
+    run_time = end_time - start_time
+    minutes = int(run_time / 60)
+    seconds = int(run_time % 60)
+    print(f'程序运行时间: {minutes} 分钟 {seconds} 秒')
+    time.sleep(5)
+
+
+start_time = time.time()
 pf = Portfolios("3006125408623189")
 pfo = pf.updata_create()
 print("Portfolios", pfo)
+protime(start_time)
 
+start_time = time.time()
 spc = SpCampaign(profile_id="3006125408623189")
 spco = spc.updata_create()
 print("SpCampaign", spco)
+protime(start_time)
 
+start_time = time.time()
 spg = SpGroup(profile_id="3006125408623189")
 spgo = spg.updata_create()
 print("SpGroup", spgo)
+protime(start_time)
 
+start_time = time.time()
 spk = SpKeyword(profile_id="3006125408623189")
 spko = spk.updata_create()
 print("SpKeyword", spko)
+protime(start_time)
 
+start_time = time.time()
 spa = SpAds(profile_id="3006125408623189")
 spao = spa.updata_create()
 print("SpAds", spao)
+protime(start_time)
 
+start_time = time.time()
 spbr = SpBudgetRecommendation(profile_id="3006125408623189")
 spbro = spbr.updata_create()
 print("SpBudgetRecommendation", spbro)
+protime(start_time)
 
+start_time = time.time()
 sptb = SpTargetsBidRecommendations(profile_id="3006125408623189")
 sptbo = sptb.updata_create()
 print("SpTargetsBidRecommendations", sptbo)
+protime(start_time)
 
+start_time = time.time()
 spt = SpTargets(profile_id="3006125408623189")
 spto = spt.updata_create()
 print("SpTargets", spto)
+protime(start_time)
 
+start_time = time.time()
 sptbv2 = SpTargetsBidRecommendationsV2(profile_id="3006125408623189")
 sptbv2o = sptbv2.updata_create()
 print("SpTargetsBidRecommendationsV2", sptbv2o)
+protime(start_time)
 
+start_time = time.time()
 spnt = SpNegativeTarget(profile_id="3006125408623189")
 spnto = spnt.updata_create()
 print('SpNegativeTarget', spnto)
+protime(start_time)
 
+start_time = time.time()
 spnk = SpNegativeKeyword(profile_id="3006125408623189")
 spnko = spnk.updata_create()
 print('SpNegativeKeyword', spnko)
+protime(start_time)
 
 
+start_time = time.time()
 sbc = SbCampaign(profile_id="3006125408623189")
 sbco = sbc.updata_create()
 print("SbCampaign", sbco)
+protime(start_time)
 
+start_time = time.time()
 sbg = SbGroup(profile_id="3006125408623189")
 sbgo = sbg.updata_create()
 print("SbGroup", sbgo)
+protime(start_time)
 
+start_time = time.time()
 sbk = SbKeyword(profile_id="3006125408623189")
 sbko = sbk.updata_create()
 print("SbKeyword", sbko)
+protime(start_time)
 
+start_time = time.time()
 sba = SbAds(profile_id="3006125408623189")
 sbao = sba.updata_create()
 print("SbAds", sbao)
+protime(start_time)
 
+start_time = time.time()
 sbkbr = SbkeywordsBidRecommendations(profile_id="3006125408623189")
 sbkbro = sbkbr.updata_create()
 print("SbkeywordsBidRecommendations", sbkbro)
+protime(start_time)
 
+start_time = time.time()
 sbt = SbTargets(profile_id="3006125408623189")
 sbto = sbt.updata_create()
 print("SbTargets", sbto)
+protime(start_time)
 
+start_time = time.time()
 sbtbr = SbtargetsBidRecommendations(profile_id="3006125408623189")
 sbtbro = sbtbr.updata_create()
 print("SbtargetsBidRecommendations", sbtbro)
+protime(start_time)