|
@@ -82,75 +82,78 @@ class QplKs:
|
|
|
|
|
|
result = response["result"]
|
|
|
if result == 1:
|
|
|
- total = response["total"] # 总条数
|
|
|
- if total == 0:
|
|
|
- print(f"没有扫描到数据{content}")
|
|
|
- break
|
|
|
- star_list = response["starList"]
|
|
|
- if len(star_list) == 0 or star_list == []:
|
|
|
- break
|
|
|
- for star in star_list:
|
|
|
- print(f"扫描到一条数据{content}")
|
|
|
- user_id = star["userId"]
|
|
|
- star_id = star["starId"]
|
|
|
- name = star["name"] # 用户名
|
|
|
- kwai_id = star["kwaiId"] # 用户名id
|
|
|
- gender = star["gender"] # 性别
|
|
|
- fans_number = star["fansNumber"] # 粉丝数
|
|
|
- profile_id = star["profileId"] # 主页id
|
|
|
- star_tag_str = star["starTagStr"] # 内容类型1
|
|
|
- industry_tag_str = star["industryTagStr"] # 内容类型2
|
|
|
- photo_expect_play = star["photoExpectPlay"] # 预期播放量
|
|
|
- photo_expect_cpm = star["photoExpectCpm"] # 预期CPM
|
|
|
- photo_interaction_rate = star["photoInteractionRate"] # 互动率
|
|
|
- photo_complete_play_rate = star["photoCompletePlayRate"] # 完播率
|
|
|
- fans_increase_num = star["fansIncreaseNum"] # 粉丝增长量
|
|
|
- fans_increase_rate = star["fansIncreaseRate"] # 粉丝增长率
|
|
|
- sqlCollect.insert_ks_star_data(user_id, star_id, name, kwai_id, gender, fans_number, profile_id, star_tag_str, industry_tag_str, photo_expect_play, photo_expect_cpm, photo_interaction_rate, photo_complete_play_rate, fans_increase_num, fans_increase_rate)
|
|
|
- print(f"{star_id}-{profile_id}获取列表入库成功")
|
|
|
- cls.ks_star_works_info(star_id, profile_id)
|
|
|
- time.sleep(random.randint(10, 20))
|
|
|
- cls.ks_list_portrait_info(star_id, profile_id)
|
|
|
- time.sleep(random.randint(10, 20))
|
|
|
- # # if res == 1:
|
|
|
- # current_time = datetime.now()
|
|
|
- # formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
- # if fans_min_num == 0:
|
|
|
- # fans = f"{fans_max_num}及以下"
|
|
|
- # if fans_max_num == 0:
|
|
|
- # fans = f"{fans_min_num}及以上"
|
|
|
- # else:
|
|
|
- # fans = f"{fans_min_num}~{fans_max_num}"
|
|
|
- # values = [
|
|
|
- # [
|
|
|
- # name,
|
|
|
- # gender,
|
|
|
- # fans_number,
|
|
|
- # profile_id,
|
|
|
- # "https://www.kuaishou.com/profile/"+profile_id,
|
|
|
- # star_tag_str,
|
|
|
- # industry_tag_str,
|
|
|
- # photo_expect_play,
|
|
|
- # photo_expect_cpm,
|
|
|
- # photo_interaction_rate,
|
|
|
- # photo_complete_play_rate,
|
|
|
- # fans_increase_num,
|
|
|
- # fans_increase_rate,
|
|
|
- # fans,
|
|
|
- # formatted_time
|
|
|
- # ]
|
|
|
- # ]
|
|
|
- # Feishu.insert_columns("GjGZsmW2ahaCe4tmzDTc58tVnbe", "COyUUm", "ROWS", 1, 2)
|
|
|
- # time.sleep(0.5)
|
|
|
- # Feishu.update_values("GjGZsmW2ahaCe4tmzDTc58tVnbe", "COyUUm", "A2:Z2", values)
|
|
|
- # print(f"入库到一条数据{content}")
|
|
|
- current_page += 1
|
|
|
- if total < 20:
|
|
|
- break
|
|
|
- else:
|
|
|
- page = int(total)/20
|
|
|
- if current_page > int(page)+1:
|
|
|
+ try:
|
|
|
+ total = response["total"] # 总条数
|
|
|
+ if total == 0:
|
|
|
+ print(f"没有扫描到数据{content}")
|
|
|
break
|
|
|
+ star_list = response["starList"]
|
|
|
+ if len(star_list) == 0 or star_list == []:
|
|
|
+ break
|
|
|
+ for star in star_list:
|
|
|
+ print(f"扫描到一条数据{content}")
|
|
|
+ user_id = star["userId"]
|
|
|
+ star_id = star["starId"]
|
|
|
+ name = star["name"] # 用户名
|
|
|
+ kwai_id = star["kwaiId"] # 用户名id
|
|
|
+ gender = star["gender"] # 性别
|
|
|
+ fans_number = star["fansNumber"] # 粉丝数
|
|
|
+ profile_id = star["profileId"] # 主页id
|
|
|
+ star_tag_str = star["starTagStr"] # 内容类型1
|
|
|
+ industry_tag_str = star["industryTagStr"] # 内容类型2
|
|
|
+ photo_expect_play = star["photoExpectPlay"] # 预期播放量
|
|
|
+ photo_expect_cpm = star["photoExpectCpm"] # 预期CPM
|
|
|
+ photo_interaction_rate = star["photoInteractionRate"] # 互动率
|
|
|
+ photo_complete_play_rate = star["photoCompletePlayRate"] # 完播率
|
|
|
+ fans_increase_num = star["fansIncreaseNum"] # 粉丝增长量
|
|
|
+ fans_increase_rate = star["fansIncreaseRate"] # 粉丝增长率
|
|
|
+ sqlCollect.insert_ks_star_data(user_id, star_id, name, kwai_id, gender, fans_number, profile_id, star_tag_str, industry_tag_str, photo_expect_play, photo_expect_cpm, photo_interaction_rate, photo_complete_play_rate, fans_increase_num, fans_increase_rate)
|
|
|
+ print(f"{star_id}-{profile_id}获取列表入库成功")
|
|
|
+ cls.ks_star_works_info(star_id, profile_id)
|
|
|
+ time.sleep(random.randint(10, 20))
|
|
|
+ cls.ks_list_portrait_info(star_id, profile_id)
|
|
|
+ time.sleep(random.randint(10, 20))
|
|
|
+ # # if res == 1:
|
|
|
+ # current_time = datetime.now()
|
|
|
+ # formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ # if fans_min_num == 0:
|
|
|
+ # fans = f"{fans_max_num}及以下"
|
|
|
+ # if fans_max_num == 0:
|
|
|
+ # fans = f"{fans_min_num}及以上"
|
|
|
+ # else:
|
|
|
+ # fans = f"{fans_min_num}~{fans_max_num}"
|
|
|
+ # values = [
|
|
|
+ # [
|
|
|
+ # name,
|
|
|
+ # gender,
|
|
|
+ # fans_number,
|
|
|
+ # profile_id,
|
|
|
+ # "https://www.kuaishou.com/profile/"+profile_id,
|
|
|
+ # star_tag_str,
|
|
|
+ # industry_tag_str,
|
|
|
+ # photo_expect_play,
|
|
|
+ # photo_expect_cpm,
|
|
|
+ # photo_interaction_rate,
|
|
|
+ # photo_complete_play_rate,
|
|
|
+ # fans_increase_num,
|
|
|
+ # fans_increase_rate,
|
|
|
+ # fans,
|
|
|
+ # formatted_time
|
|
|
+ # ]
|
|
|
+ # ]
|
|
|
+ # Feishu.insert_columns("GjGZsmW2ahaCe4tmzDTc58tVnbe", "COyUUm", "ROWS", 1, 2)
|
|
|
+ # time.sleep(0.5)
|
|
|
+ # Feishu.update_values("GjGZsmW2ahaCe4tmzDTc58tVnbe", "COyUUm", "A2:Z2", values)
|
|
|
+ # print(f"入库到一条数据{content}")
|
|
|
+ current_page += 1
|
|
|
+ if total < 20:
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ page = int(total)/20
|
|
|
+ if current_page > int(page)+1:
|
|
|
+ break
|
|
|
+ except Exception as e:
|
|
|
+ print(f"{e}")
|
|
|
|
|
|
"""
|
|
|
传播表现
|
|
@@ -176,26 +179,31 @@ class QplKs:
|
|
|
response = response.json()
|
|
|
result = response['result']
|
|
|
if result == 1:
|
|
|
- star_work_report = response['starWorksInfo']['starWorkReport']
|
|
|
- pplay_median_data = star_work_report['pplayMedianData'] # 播放量中位数
|
|
|
- pplay_median_data_90 = pplay_median_data['90'] # 获取键 '90' 对应的值
|
|
|
- pplay_median_data_30 = pplay_median_data['30'] # 获取键 '30' 对应的值
|
|
|
- pphoto_cnt_data = star_work_report['pphotoCntData'] # 视频数量
|
|
|
- pphoto_cnt_data_90 = pphoto_cnt_data['90'] # 获取键 '90' 对应的值
|
|
|
- pphoto_cnt_data_30 = pphoto_cnt_data['30'] # 获取键 '30' 对应的值
|
|
|
- pavg_video_duration_data = star_work_report['pavgVideoDurationData'] # 平均时长
|
|
|
-
|
|
|
- pavg_video_duration_data_90 = f"{float(pavg_video_duration_data['90']):.3f}%" # 获取键 '90' 对应的值
|
|
|
- pavg_video_duration_data_30 = f"{float(pavg_video_duration_data['30']):.3f}%" # 获取键 '30' 对应的值
|
|
|
- pavg_like_cnt_data = star_work_report['pavgLikeCntData'] # 平均点赞
|
|
|
- star_work_report_90 = pavg_like_cnt_data['90'] # 获取键 '90' 对应的值
|
|
|
- star_work_report_30 = pavg_like_cnt_data['30'] # 获取键 '30' 对应的值
|
|
|
- pavg_share_cnt_data = star_work_report['pavgShareCntData'] # 平均分享
|
|
|
- pavg_share_cnt_90 = pavg_share_cnt_data['90'] # 获取键 '90' 对应的值
|
|
|
- pavg_share_cnt_30 = pavg_share_cnt_data['30'] # 获取键 '30' 对应的值
|
|
|
- sqlCollect.insert_ks_star_works_info(star_id, profile_id, pplay_median_data_90, pplay_median_data_30, pphoto_cnt_data_90, pphoto_cnt_data_30, pavg_video_duration_data_90, pavg_video_duration_data_30, star_work_report_90, star_work_report_30, pavg_share_cnt_90, pavg_share_cnt_30)
|
|
|
- print(f"{star_id}-{profile_id}获取传播表现入库成功")
|
|
|
-
|
|
|
+ try:
|
|
|
+ star_work_report = response['starWorksInfo']['starWorkReport']
|
|
|
+ pplay_median_data = star_work_report['pplayMedianData'] # 播放量中位数
|
|
|
+ pplay_median_data_90 = pplay_median_data['90'] # 获取键 '90' 对应的值
|
|
|
+ pplay_median_data_30 = pplay_median_data['30'] # 获取键 '30' 对应的值
|
|
|
+ pphoto_cnt_data = star_work_report['pphotoCntData'] # 视频数量
|
|
|
+ pphoto_cnt_data_90 = pphoto_cnt_data['90'] # 获取键 '90' 对应的值
|
|
|
+ pphoto_cnt_data_30 = pphoto_cnt_data['30'] # 获取键 '30' 对应的值
|
|
|
+ pavg_video_duration_data = star_work_report['pavgVideoDurationData'] # 平均时长
|
|
|
+ # 处理 '90' 键的值
|
|
|
+ value_90 = pavg_video_duration_data['90']
|
|
|
+ pavg_video_duration_data_90 = f"{float(value_90):.3f}%" if value_90 else "0.000%"
|
|
|
+ # 处理 '30' 键的值
|
|
|
+ value_30 = pavg_video_duration_data['30']
|
|
|
+ pavg_video_duration_data_30 = f"{float(value_30):.3f}%" if value_30 else "0.000%"
|
|
|
+ pavg_like_cnt_data = star_work_report['pavgLikeCntData'] # 平均点赞
|
|
|
+ star_work_report_90 = pavg_like_cnt_data['90'] # 获取键 '90' 对应的值
|
|
|
+ star_work_report_30 = pavg_like_cnt_data['30'] # 获取键 '30' 对应的值
|
|
|
+ pavg_share_cnt_data = star_work_report['pavgShareCntData'] # 平均分享
|
|
|
+ pavg_share_cnt_90 = pavg_share_cnt_data['90'] # 获取键 '90' 对应的值
|
|
|
+ pavg_share_cnt_30 = pavg_share_cnt_data['30'] # 获取键 '30' 对应的值
|
|
|
+ sqlCollect.insert_ks_star_works_info(star_id, profile_id, pplay_median_data_90, pplay_median_data_30, pphoto_cnt_data_90, pphoto_cnt_data_30, pavg_video_duration_data_90, pavg_video_duration_data_30, star_work_report_90, star_work_report_30, pavg_share_cnt_90, pavg_share_cnt_30)
|
|
|
+ print(f"{star_id}-{profile_id}获取传播表现入库成功")
|
|
|
+ except Exception as e:
|
|
|
+ print(f"{star_id}-{profile_id}:{e}")
|
|
|
else:
|
|
|
print(f"{star_id}-{profile_id}获取传播表现失败")
|
|
|
|
|
@@ -225,34 +233,42 @@ class QplKs:
|
|
|
if result == 1:
|
|
|
viewer_portrait = response['data']['viewerPortrait']
|
|
|
sex_percentage = viewer_portrait['sexPercentage'] # 性别占比
|
|
|
- for sex in sex_percentage:
|
|
|
- sex_type = 'sex_percentage'
|
|
|
- sex_name = sex['label']
|
|
|
- sex_proportion = f"{float(sex['value']):.3f}%"
|
|
|
- sqlCollect.insert_ks_list_portrait_info(star_id, profile_id, sex_type, sex_name, sex_proportion)
|
|
|
- age_percentage = viewer_portrait['agePercentage'] # 年龄占比
|
|
|
- for age in age_percentage:
|
|
|
- age_type = 'age_percentage'
|
|
|
- age_name = age['label']
|
|
|
- age_proportion = f"{float(age['value']):.3f}%"
|
|
|
- sqlCollect.insert_ks_list_portrait_info(star_id, profile_id, age_type, age_name, age_proportion)
|
|
|
- area_percentage = viewer_portrait['areaPercentage'] # 城市占比
|
|
|
- for area in area_percentage:
|
|
|
- area_type = 'area_percentage'
|
|
|
- area_name = area['label']
|
|
|
- area_proportion = f"{float(area['value']):.3f}%"
|
|
|
- sqlCollect.insert_ks_list_portrait_info(star_id, profile_id, area_type, area_name, area_proportion)
|
|
|
- mobile_brand_percentage = viewer_portrait['mobileBrandPercentage'] # 设备占比
|
|
|
- for brand in mobile_brand_percentage:
|
|
|
- brand_type = 'mobile_brand_percentage'
|
|
|
- brand_name = brand['label']
|
|
|
- brand_proportion = f"{float(brand['value']):.3f}%"
|
|
|
- sqlCollect.insert_ks_list_portrait_info(star_id, profile_id, brand_type, brand_name, brand_proportion)
|
|
|
+ try:
|
|
|
+ for sex in sex_percentage:
|
|
|
+ sex_type = 'sex_percentage'
|
|
|
+ sex_name = sex['label']
|
|
|
+ value = sex['value']
|
|
|
+ sex_proportion = f"{float(value):.3f}%" if value else "0.000%"
|
|
|
+ sqlCollect.insert_ks_list_portrait_info(star_id, profile_id, sex_type, sex_name, sex_proportion)
|
|
|
+ age_percentage = viewer_portrait['agePercentage'] # 年龄占比
|
|
|
+ for age in age_percentage:
|
|
|
+ age_type = 'age_percentage'
|
|
|
+ age_name = age['label']
|
|
|
+ value = age['value']
|
|
|
+ age_proportion = f"{float(value):.3f}%" if value else "0.000%"
|
|
|
+ sqlCollect.insert_ks_list_portrait_info(star_id, profile_id, age_type, age_name, age_proportion)
|
|
|
+ area_percentage = viewer_portrait['areaPercentage'] # 城市占比
|
|
|
+ for area in area_percentage:
|
|
|
+ area_type = 'area_percentage'
|
|
|
+ area_name = area['label']
|
|
|
+ value = area['value']
|
|
|
+ area_proportion = f"{float(value):.3f}%" if value else "0.000%"
|
|
|
+ sqlCollect.insert_ks_list_portrait_info(star_id, profile_id, area_type, area_name, area_proportion)
|
|
|
+ mobile_brand_percentage = viewer_portrait['mobileBrandPercentage'] # 设备占比
|
|
|
+ for brand in mobile_brand_percentage:
|
|
|
+ brand_type = 'mobile_brand_percentage'
|
|
|
+ brand_name = brand['label']
|
|
|
+ value = brand['value']
|
|
|
+ brand_proportion = f"{float(value):.3f}%" if value else "0.000%"
|
|
|
+ sqlCollect.insert_ks_list_portrait_info(star_id, profile_id, brand_type, brand_name, brand_proportion)
|
|
|
+ except Exception as e:
|
|
|
+ print(f"{star_id}-{profile_id}:{e}")
|
|
|
mobile_price_percentage = viewer_portrait['mobilePricePercentage'] # 设备价格占比
|
|
|
for price in mobile_price_percentage:
|
|
|
price_type = 'mobile_price_percentage'
|
|
|
price_name = price['label']
|
|
|
- price_proportion = f"{float(price['value']):.3f}%"
|
|
|
+ value = price['value']
|
|
|
+ price_proportion = f"{float(value):.3f}%" if value else "0.000%"
|
|
|
sqlCollect.insert_ks_list_portrait_info(star_id, profile_id, price_type, price_name, price_proportion)
|
|
|
print(f"{star_id}-{profile_id}获取受众分析入库成功")
|
|
|
else:
|