Explorar o código

Merge branch 'wengao'

wengao hai 1 ano
pai
achega
a83d40379f
Modificáronse 2 ficheiros con 246 adicións e 0 borrados
  1. 71 0
      sync_amz_data/tasks/datainsert/pl_update.py
  2. 175 0
      wg_alldatainsert.py

+ 71 - 0
sync_amz_data/tasks/datainsert/pl_update.py

@@ -0,0 +1,71 @@
+from sync_amz_data.DataTransform.Data_ETL import SP_ETL
+
+import requests
+from urllib.parse import urljoin
+from sync_amz_data.public.amz_ad_client import SPClient
+from sync_amz_data.settings import AWS_LWA_CLIENT
+import pandas as pd
+import json
+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 ProductLineDetail:
+    def __init__(self, profile_id):
+        self.profile_id = profile_id
+        self.re_url_path = "api/ad_manage/profiles/"
+        self.upcreate_url_path = "api/sellers/productlinedetail/update/pasin"
+        self.heads = {'X-Token': "da4ab6bc5cbf1dfa"}
+        self.refresh_token = self.get_refresh_token()
+        self.lwa_client_id = AWS_LWA_CLIENT['lwa_client_id']
+        self.lwa_client_secret = AWS_LWA_CLIENT['lwa_client_secret']
+        self.AWS_CREDENTIALS = {
+            'lwa_client_id': self.lwa_client_id,
+            'lwa_client_secret': self.lwa_client_secret,
+            'refresh_token': self.refresh_token,
+            'profile_id': self.profile_id
+        }
+        
+    def get_refresh_token(self):
+        params = {'profile_id': self.profile_id}
+        heads = self.heads
+        url_path = self.re_url_path
+        tem = request(url_path=url_path, head=heads, params=params)
+        if tem.get('data') is not None:
+            _ = tem.get('data')
+            out = _[0].get('refresh_token')
+        else:
+            out = None
+        return out
+    
+    def updata_create(self):
+        heads = self.heads
+        url_path = self.upcreate_url_path
+        params = {'profileId': self.profile_id}
+        tem = request(url_path=url_path, head=heads, method="GET", params=params)
+        return tem
+    
+if __name__ == '__main__':
+    a = ProductLineDetail(profile_id="3006125408623189")
+    # out = a.get_sptargets_data()
+    out = a.updata_create()
+    print(out)

+ 175 - 0
wg_alldatainsert.py

@@ -0,0 +1,175 @@
+from sync_amz_data.tasks.datainsert.mysql_datainsert_portfolios import Portfolios
+from sync_amz_data.tasks.datainsert.SP.mysql_datainsert_spcampaign import SpCampaign
+from sync_amz_data.tasks.datainsert.SP.mysql_datainsert_spgroup import SpGroup
+from sync_amz_data.tasks.datainsert.SP.mysql_datainsert_spkeyword import SpKeyword
+from sync_amz_data.tasks.datainsert.SP.mysql_datainsert_sp_budget_recommendation import SpBudgetRecommendation
+from sync_amz_data.tasks.datainsert.SP.mysql_datainsert_spads import SpAds
+from sync_amz_data.tasks.datainsert.SP.mysql_datainsert_sp_targetsbid_recommendations import SpTargetsBidRecommendations
+from sync_amz_data.tasks.datainsert.SP.mysql_datainsert_sptarget import SpTargets
+from sync_amz_data.tasks.datainsert.SP.mysql_datainsert_sp_targetsbid_recommendations_v2 import SpTargetsBidRecommendationsV2
+from sync_amz_data.tasks.datainsert.SP.mysql_datainsert_spnegativekeyword import SpNegativeKeyword
+from sync_amz_data.tasks.datainsert.SP.mysql_datainsert_spnegativetarget import SpNegativeTarget
+
+from sync_amz_data.tasks.datainsert.SB.mysql_datainsert_sbcampaign import SbCampaign
+from sync_amz_data.tasks.datainsert.SB.mysql_datainsert_sbgroup import SbGroup
+from sync_amz_data.tasks.datainsert.SB.mysql_datainsert_sbkeyword_v3 import SbKeyword
+from sync_amz_data.tasks.datainsert.SB.mysql_datainsert_sbads import SbAds
+from sync_amz_data.tasks.datainsert.SB.mysql_datainsert_sb_keywordsbid_recommendations_v3 import SbkeywordsBidRecommendations
+from sync_amz_data.tasks.datainsert.SB.mysql_datainsert_sbtarget_v3 import SbTargets
+from sync_amz_data.tasks.datainsert.SB.mysql_datainsert_sbtargetbid_recommendations_v3 import SbtargetsBidRecommendations
+from sync_amz_data.tasks.datainsert.SB.mysql_datainsert_sbnegativekeyword import SbNegtiveKeyword
+from sync_amz_data.tasks.datainsert.SB.mysql_datainsert_sbthemetargeting_v3 import SbThemeTargeting
+
+from sync_amz_data.tasks.datainsert.mysql_datainsert_assets import Assets
+from sync_amz_data.tasks.datainsert.categories_updata import Categories
+from sync_amz_data.tasks.datainsert.pl_update import ProductLineDetail
+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()
+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()
+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()
+spt = SpTargets(profile_id="3006125408623189")
+spto = spt.updata_create()
+print("SpTargets", spto)
+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()
+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)
+
+start_time = time.time()
+Sbnk = SbNegtiveKeyword(profile_id="3006125408623189")
+Sbnko = Sbnk.updata_create()
+print("SbNegtiveKeyword", Sbnko)
+protime(start_time)
+
+start_time = time.time()
+Sbtt = SbThemeTargeting(profile_id="3006125408623189")
+Sbtto = Sbtt.updata_create()
+print("SbThemeTargeting", Sbtto)
+protime(start_time)
+
+start_time = time.time()
+ass = Assets(profile_id="3006125408623189")
+asso = ass.updata_create()
+print("Assets", asso)
+protime(start_time)
+
+start_time = time.time()
+plu = ProductLineDetail(profile_id="3006125408623189")
+pluo = plu.updata_create()
+print("PlUpdate", pluo)
+protime(start_time)