Selaa lähdekoodia

Merge branch 'wengao' of ASJ_ADS/sync_amz_data into master

wengao 1 vuosi sitten
vanhempi
commit
cdecdd776b

+ 24 - 0
sync_amz_data/tasks/datainsert/SP/mysql_datainsert_spcampaign.py

@@ -27,6 +27,26 @@ def request(url_path: str, method: str = "GET", head: dict = None, params: dict
     return resp.json()
 
 
+def convert_row(row):
+    l_t = None
+    l_p = None
+    l_r = None
+    if len(row['dyp']) > 0:
+        for i in row['dyp']:
+            a = json.loads(i)
+            if 'placement' in a:
+                if a['placement'] == "PLACEMENT_TOP":
+                    l_t = a['percentage']
+                if a['placement'] == "PLACEMENT_PRODUCT_PAGE":
+                    l_p = a['percentage']
+                if a['placement'] == "PLACEMENT_REST_OF_SEARCH":
+                    l_r = a['percentage']
+    return l_t, l_p, l_r
+# row['top'],row['product_page'],row['rest_of_search']
+
+def parse_dict_list(lst):
+    return [json.dumps(json_str) for json_str in lst]
+
 class SpCampaign:
     def __init__(self, profile_id, portfolioId: list = None):
         self.profile_id = profile_id
@@ -84,6 +104,10 @@ class SpCampaign:
         tem = pd.concat([old, df]).reset_index()
         tem.drop(columns='index', inplace=True)
         tem.columns = [i.replace(".", "_") for i in tem.columns]
+        tem['dyp'] = tem['dynamicBidding_placementBidding']
+        tem.dyp = tem.dyp.apply(parse_dict_list)
+        tem[['top', 'product_page', 'rest_of_search']] = tem.apply(convert_row, axis=1, result_type='expand')
+        tem.drop(columns='dyp', inplace=True)
         tem.rename(columns={
             'name': 'campaignName',
             'portfolioId': 'portfolio',

+ 1 - 0
sync_amz_data/tasks/datainsert/SP/mysql_datainsert_sptarget.py

@@ -95,3 +95,4 @@ if __name__ == '__main__':
     # out = a.get_sptargets_data()
     out = a.updata_create()
     print(out)
+