|
@@ -27,12 +27,25 @@ def request(url_path: str, method: str = "GET", head: dict = None, params: dict
|
|
return resp.json()
|
|
return resp.json()
|
|
|
|
|
|
|
|
|
|
|
|
+def convert_row(row, klist, tlist):
|
|
|
|
+ adgroupid = row['adGroupId']
|
|
|
|
+ if adgroupid in klist:
|
|
|
|
+ expressions = "keyword"
|
|
|
|
+ elif adgroupid in tlist:
|
|
|
|
+ expressions = "target"
|
|
|
|
+ else:
|
|
|
|
+ expressions = "notmatch"
|
|
|
|
+ return expressions
|
|
|
|
+
|
|
|
|
+
|
|
class SpGroup:
|
|
class SpGroup:
|
|
def __init__(self, profile_id, campaignId: list = None):
|
|
def __init__(self, profile_id, campaignId: list = None):
|
|
self.profile_id = profile_id
|
|
self.profile_id = profile_id
|
|
self.portfolioId = campaignId
|
|
self.portfolioId = campaignId
|
|
self.re_url_path = "api/ad_manage/profiles/"
|
|
self.re_url_path = "api/ad_manage/profiles/"
|
|
self.upcreate_url_path = "api/ad_manage/spgroups/updata/?updata=1"
|
|
self.upcreate_url_path = "api/ad_manage/spgroups/updata/?updata=1"
|
|
|
|
+ self.kid_url_path = "api/ad_manage/spkeywordsadgroupId/"
|
|
|
|
+ self.tid_url_path = "api/ad_manage/sptargetsadgroupId/"
|
|
self.heads = {'X-Token': "da4ab6bc5cbf1dfa"}
|
|
self.heads = {'X-Token': "da4ab6bc5cbf1dfa"}
|
|
self.refresh_token = self.get_refresh_token()
|
|
self.refresh_token = self.get_refresh_token()
|
|
self.lwa_client_id = AWS_LWA_CLIENT['lwa_client_id']
|
|
self.lwa_client_id = AWS_LWA_CLIENT['lwa_client_id']
|
|
@@ -63,7 +76,45 @@ class SpGroup:
|
|
return df_group
|
|
return df_group
|
|
#----------------------------
|
|
#----------------------------
|
|
|
|
|
|
|
|
+ def get_keyword_adgroupid_list(self):
|
|
|
|
+ heads = self.heads
|
|
|
|
+ url_path = self.kid_url_path
|
|
|
|
+ data = []
|
|
|
|
+ page = 1
|
|
|
|
+ params = {'limit': 999, 'page': page}
|
|
|
|
+ tem = request(url_path=url_path, head=heads, params=params)
|
|
|
|
+ data.extend(tem.get('data'))
|
|
|
|
+ while tem.get('is_next') is True:
|
|
|
|
+ page += 1
|
|
|
|
+ params = {'profile_id': self.profile_id, 'limit': 999, 'page': page}
|
|
|
|
+ tem = request(url_path=url_path, head=heads, params=params)
|
|
|
|
+ data.extend(tem.get('data'))
|
|
|
|
+ df = pd.json_normalize(data)
|
|
|
|
+ df.drop_duplicates(inplace=True)
|
|
|
|
+ kglist = list(df.adGroupId)
|
|
|
|
+ return kglist
|
|
|
|
+
|
|
|
|
+ def get_target_adgroupid_list(self):
|
|
|
|
+ heads = self.heads
|
|
|
|
+ url_path = self.tid_url_path
|
|
|
|
+ data = []
|
|
|
|
+ page = 1
|
|
|
|
+ params = {'limit': 999, 'page': page}
|
|
|
|
+ tem = request(url_path=url_path, head=heads, params=params)
|
|
|
|
+ data.extend(tem.get('data'))
|
|
|
|
+ while tem.get('is_next') is True:
|
|
|
|
+ page += 1
|
|
|
|
+ params = {'profile_id': self.profile_id, 'limit': 999, 'page': page}
|
|
|
|
+ tem = request(url_path=url_path, head=heads, params=params)
|
|
|
|
+ data.extend(tem.get('data'))
|
|
|
|
+ df = pd.json_normalize(data)
|
|
|
|
+ df.drop_duplicates(inplace=True)
|
|
|
|
+ tglist = list(df.adGroupId)
|
|
|
|
+ return tglist
|
|
|
|
+
|
|
def dataconvert(self):
|
|
def dataconvert(self):
|
|
|
|
+ tem_t = self.get_target_adgroupid_list()
|
|
|
|
+ tem_k = self.get_keyword_adgroupid_list()
|
|
df = self.get_spgroup_data()
|
|
df = self.get_spgroup_data()
|
|
df['extendedData.creationDateTime'] = pd.to_datetime(df['extendedData.creationDateTime']).dt.strftime(
|
|
df['extendedData.creationDateTime'] = pd.to_datetime(df['extendedData.creationDateTime']).dt.strftime(
|
|
'%Y-%m-%d %H:%M:%S')
|
|
'%Y-%m-%d %H:%M:%S')
|
|
@@ -83,6 +134,7 @@ class SpGroup:
|
|
'extendedData_servingStatus': 'servingStatus',
|
|
'extendedData_servingStatus': 'servingStatus',
|
|
'extendedData_servingStatusDetails': 'servingStatusDetails'
|
|
'extendedData_servingStatusDetails': 'servingStatusDetails'
|
|
}, inplace=True)
|
|
}, inplace=True)
|
|
|
|
+ tem['targetingType'] = tem.apply(convert_row, klist=tem_k, tlist=tem_t,axis=1)
|
|
json_data = json.loads(tem.to_json(orient='records', force_ascii=False))
|
|
json_data = json.loads(tem.to_json(orient='records', force_ascii=False))
|
|
return json_data
|
|
return json_data
|
|
|
|
|
|
@@ -98,6 +150,7 @@ if __name__ == '__main__':
|
|
a = SpGroup(profile_id="3006125408623189")
|
|
a = SpGroup(profile_id="3006125408623189")
|
|
out = a.updata_create()
|
|
out = a.updata_create()
|
|
# out = a.dataconvert()
|
|
# out = a.dataconvert()
|
|
|
|
+ # out = a.get_target_adgroupid_list()
|
|
print(out)
|
|
print(out)
|
|
|
|
|
|
|
|
|