liyuyi@c-top.com.cn 4 лет назад
Сommit
a8435a8500
8 измененных файлов с 161 добавлено и 0 удалено
  1. 8 0
      .idea/.gitignore
  2. 11 0
      .idea/ai_ads.iml
  3. 6 0
      .idea/inspectionProfiles/profiles_settings.xml
  4. 4 0
      .idea/misc.xml
  5. 8 0
      .idea/modules.xml
  6. 16 0
      main.py
  7. 0 0
      parse_json.py
  8. 108 0
      request_json.py

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/../../../:\ai_ads\.idea/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/

+ 11 - 0
.idea/ai_ads.iml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+  <component name="TestRunnerService">
+    <option name="PROJECT_TEST_RUNNER" value="pytest" />
+  </component>
+</module>

+ 6 - 0
.idea/inspectionProfiles/profiles_settings.xml

@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+  <settings>
+    <option name="USE_PROJECT_PROFILE" value="false" />
+    <version value="1.0" />
+  </settings>
+</component>

+ 4 - 0
.idea/misc.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/ai_ads.iml" filepath="$PROJECT_DIR$/.idea/ai_ads.iml" />
+    </modules>
+  </component>
+</project>

+ 16 - 0
main.py

@@ -0,0 +1,16 @@
+# This is a sample Python script.
+
+# Press Shift+F10 to execute it or replace it with your code.
+# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
+
+
+def print_hi(name):
+    # Use a breakpoint in the code line below to debug your script.
+    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.
+
+
+# Press the green button in the gutter to run the script.
+if __name__ == '__main__':
+    print_hi('PyCharm')
+
+# See PyCharm help at https://www.jetbrains.com/help/pycharm/

+ 0 - 0
parse_json.py


+ 108 - 0
request_json.py

@@ -0,0 +1,108 @@
+import pandas as pd
+import numpy as np
+import datetime
+import pymysql
+from sqlalchemy import create_engine
+
+# online_con_str = "mysql+pymysql://%s:%s@%s:%d/%s" % ("readonly", "hcst@2021", "139.186.27.96", 4000, "jeecg-boot")
+# engine = create_engine(online_con_str, connect_args={'charset': 'utf8'})
+
+# test_con_str = "mysql+pymysql://%s:%s@%s:%d/%s" % ("hcst", "hcst2020", "139.186.151.174", 3306, "jeecg-boot")
+# engine = create_engine(test_con_str, connect_args={'charset': 'utf8'})
+
+online_con_str = "mysql+pymysql://%s:%s@%s:%d/%s" % ("hcst", "hcst@2020", "139.186.151.174", 3306, "jeecg-boot")
+engine = create_engine(online_con_str, connect_args={'charset': 'utf8'})
+
+
+
+
+# 拼接请求的json
+# example: 整个项目近30天内,消耗top10的视频,创建组
+account_id = 9556344
+request_dict = {}
+# 1、读取 客户策略表中 status = 1 的记录 (ctop_ai_kuaishou_advertiser_strategy)
+get_advertiser_strategy_sql = """
+select * 
+from ctop_ai_kuaishou_advertiser_strategy 
+where account_id = %d 
+and status = 1
+""" % account_id
+advertiser_strategy_df = pd.read_sql(get_advertiser_strategy_sql, engine)
+advertiser_strategy_drop_cols = ['id', 'status', 'create_time', 'effective_time', 'expiry_time']
+advertiser_strategy_df.drop(columns=advertiser_strategy_drop_cols, inplace=True)
+request_dict['advertiser_strategy_info'] = advertiser_strategy_df.T.to_dict()[0]
+
+# 2、拼接请求的json
+
+
+
+# 2.1 获取需要创建广告组所需要的视频
+# 调用于蒙的视频接口
+
+# 获取视频方式一
+days = 30
+num = 10
+sql = """
+select * from ctop_kuaishou_video_get
+        where account_id = %d
+        and signature in
+        (
+        select
+            daily_material.signature
+        from
+        ctop_kuaishou_report_daily_material daily_material
+        inner join
+        ctop_user_allocation allocation
+        on daily_material.account_id = allocation.account_id
+        where  allocation.project_id in (select project_id from ctop_user_allocation where account_id = %d)
+        and  to_days(now()) - to_days(daily_material.stat_date) <= %d
+        and daily_material.signature is not null
+        GROUP BY daily_material.signature
+        order by sum(daily_material.charge) desc
+        limit %d
+        )
+""" % (account_id, account_id, days, num)
+# video_df = pd.read_sql(sql, engine)
+# print(video_df.shape)
+
+# 获取视频方式二
+# 离线分析手动提取 signature,然后创建广告组
+# signature_list = ['f17059ef15d5940a43bd38f9b13dc551', 'c0065cbd882d94c7c0a808db68f73666']
+# sql = """
+# select * from ctop_kuaishou_video_get
+#         where account_id = %d
+#         and signature in %s
+# """ % (account_id, tuple(signature_list))
+# video_df = pd.read_sql(sql, engine)
+# print(video_df)
+
+# 2.1 计划层级的参数
+campaign_name = "户14-上下滑&信息流-跑量视频-剪辑-低价-低价包邮-活动-年龄18岁以上-单出价-" + \
+                datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")
+# campaign_id 为空表示需要创建广告计划, 不为空则表示在该广告计划下新增广告组
+campaign_dict = {}
+campaign_id = None
+campaign_dict['campaign_name'] = campaign_name
+campaign_dict['campaign_id'] = campaign_id
+campaign_dict['campaign_type'] = 2
+campaign_dict['day_budget'] = None
+campaign_dict['day_budget_schedule'] = None
+campaign_dict['operation_type'] = "add"
+
+request_dict['campaign'] = campaign_dict
+
+
+# 2.2 组层级的参数
+
+
+
+
+
+
+
+
+
+
+
+
+