Kaynağa Gözat

代码优化;添加Categories更新接口

wengao 1 yıl önce
ebeveyn
işleme
7ac54fcdae

+ 4 - 2
sync_amz_data/tasks/datainsert/SP/mysql_datainsert_sp_targetsbid_recommendations.py

@@ -94,6 +94,8 @@ class SpTargetsBidRecommendations:
                         data = j.get('bidRecommendationsForTargetingExpressions')
                         out_data.extend(data)
                 temtest = pd.json_normalize(out_data)
+                if len(temtest) == 0:
+                    temtest = pd.DataFrame(data=[], columns=['value', 'type'])
                 temtest.rename(columns={'targetingExpression.value': 'value'}, inplace=True)
                 temtest.rename(columns={'targetingExpression.type': 'type'}, inplace=True)
                 df_tem = pd.merge(left=temtest, right=k_id_text_df, on=['value', 'type'], how='left')
@@ -124,6 +126,6 @@ class SpTargetsBidRecommendations:
 
 if __name__ == '__main__':
     a = SpTargetsBidRecommendations(profile_id="3006125408623189")
-    out = a.get_sptargetsbidrecommendation_data()
-    # out = a.updata_create()
+    # out = a.get_sptargetsbidrecommendation_data()
+    out = a.updata_create()
     print(out)

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

@@ -21,6 +21,7 @@ from SB.mysql_datainsert_sbnegativekeyword import SbNegtiveKeyword
 from SB.mysql_datainsert_sbthemetargeting_v3 import SbThemeTargeting
 
 from mysql_datainsert_assets import Assets
+from categories_updata import Categories
 
 import time
 
@@ -34,6 +35,12 @@ def protime(start_time):
     time.sleep(5)
 
 
+start_time = time.time()
+cg = Categories(profile_id="3006125408623189")
+cgo = cg.updata_create()
+print("Categories", cgo)
+protime(start_time)
+
 start_time = time.time()
 pf = Portfolios("3006125408623189")
 pfo = pf.updata_create()

+ 44 - 0
sync_amz_data/tasks/datainsert/categories_updata.py

@@ -0,0 +1,44 @@
+import requests
+from urllib.parse import urljoin
+from sync_amz_data.tasks.datainsert.wg import LADS
+
+
+class RateLimitError(Exception):
+    def __init__(self, retry_after: str = None):
+        self.retry_after = retry_after
+
+
+def request(url_path: str, method: str = "GET", head: dict = None, params: dict = None, body: dict = None, AD=LADS):
+    ADS = AD
+    resp = requests.session().request(
+        method=method,
+        url=urljoin(ADS, url_path),
+        headers=head,
+        params=params,
+        json=body,
+    )
+    if resp.status_code == 429:
+        raise RateLimitError(resp.headers.get("Retry-After"))
+    if resp.status_code >= 400:
+        raise Exception(resp.text)
+    return resp.json()
+
+
+class Categories:
+    def __init__(self, profile_id):
+        self.profile_id = profile_id
+        self.upcreate_url_path = "api/ad_manage/targetable/categories/updata/"
+        self.heads = {'X-Token': "da4ab6bc5cbf1dfa"}
+
+    def updata_create(self):
+        heads = self.heads
+        url_path = self.upcreate_url_path
+        params = {"profile_id": self.profile_id}
+        tem = request(url_path=url_path, head=heads, method="GET", params=params)
+        return tem
+
+
+if __name__ == '__main__':
+    a = Categories(profile_id="3006125408623189")
+    out = a.updata_create()
+    print(out)

+ 1 - 0
sync_amz_data/tasks/datainsert/mysql_datainsert_assets.py

@@ -91,6 +91,7 @@ class Assets:
         df['creationTime'] = pd.to_datetime(df['creationTime'], unit='ms').dt.strftime('%Y-%m-%d')
         df['lastUpdatedTime'] = pd.to_datetime(df['lastUpdatedTime'], unit='ms').dt.strftime('%Y-%m-%d')
         df['assetSubTypeList'] = df['assetSubTypeList'].astype(str)
+        df['isDownloadable'] = df['isDownloadable'].astype(str)
         json_data = json.loads(df.to_json(orient='records', force_ascii=False))
         return json_data
 

+ 2 - 1
sync_amz_data/tasks/datainsert/wg.py

@@ -1 +1,2 @@
-LADS = "http://192.168.1.18:8001/"
+LADS = "http://192.168.1.19:8001/"
+# LADS = "https://ads.vzzon.com"