|
@@ -1,27 +1,25 @@
|
|
-import sys
|
|
|
|
import requests
|
|
import requests
|
|
import hashlib
|
|
import hashlib
|
|
import time
|
|
import time
|
|
import json
|
|
import json
|
|
-import pymysql
|
|
|
|
import logging
|
|
import logging
|
|
import random
|
|
import random
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
-from datetime import datetime
|
|
|
|
from model.DateUtils import DateUtils
|
|
from model.DateUtils import DateUtils
|
|
from model.DataBaseUtils import MysqlUtils
|
|
from model.DataBaseUtils import MysqlUtils
|
|
-db = MysqlUtils()
|
|
|
|
from model.DingTalkUtils import DingTalkUtils
|
|
from model.DingTalkUtils import DingTalkUtils
|
|
-# logging.getLogger().setLevel(logging.WARNING)
|
|
|
|
|
|
+
|
|
|
|
+db = MysqlUtils()
|
|
du = DateUtils()
|
|
du = DateUtils()
|
|
|
|
|
|
|
|
+
|
|
def md5value(s):
|
|
def md5value(s):
|
|
- md5 = hashlib.md5()
|
|
|
|
- md5.update(s.encode("utf-8"))
|
|
|
|
- return md5.hexdigest()
|
|
|
|
|
|
+ md5 = hashlib.md5()
|
|
|
|
+ md5.update(s.encode("utf-8"))
|
|
|
|
+ return md5.hexdigest()
|
|
|
|
|
|
|
|
|
|
-def daily_reports_get(access_token, account_id, st, et,level, fields):
|
|
|
|
|
|
+def daily_reports_get(access_token, account_id, st, et, level, fields):
|
|
interface = 'daily_reports/get'
|
|
interface = 'daily_reports/get'
|
|
url = 'https://api.e.qq.com/v1.1/' + interface
|
|
url = 'https://api.e.qq.com/v1.1/' + interface
|
|
|
|
|
|
@@ -51,86 +49,83 @@ def daily_reports_get(access_token, account_id, st, et,level, fields):
|
|
|
|
|
|
r = requests.get(url, params=parameters).json()
|
|
r = requests.get(url, params=parameters).json()
|
|
if r['code'] != 0:
|
|
if r['code'] != 0:
|
|
- print(r['code'], r['message'])
|
|
|
|
- DingTalkUtils.send('消耗日报请求超频')
|
|
|
|
|
|
+ logging.warning(str(r['code']) + str(r['message']))
|
|
|
|
+ DingTalkUtils().send('消耗日报请求超频' + '\n' + str(r['code']) + str(r['message']))
|
|
|
|
|
|
return r
|
|
return r
|
|
|
|
|
|
|
|
|
|
-def get_q_data(y,li,st,et):
|
|
|
|
- c = daily_reports_get(y[2], y[0],st,et, "REPORT_LEVEL_ADVERTISER", (
|
|
|
|
|
|
+def get_q_data(y, li, st, et):
|
|
|
|
+ c = daily_reports_get(y[2], y[0], st, et, "REPORT_LEVEL_ADVERTISER", (
|
|
'date', 'view_count', 'valid_click_count', 'ctr', 'cpc', 'cost', 'web_order_count', 'web_order_rate',
|
|
'date', 'view_count', 'valid_click_count', 'ctr', 'cpc', 'cost', 'web_order_count', 'web_order_rate',
|
|
'web_order_cost', 'follow_count', 'order_amount', 'order_roi', 'platform_page_view_count',
|
|
'web_order_cost', 'follow_count', 'order_amount', 'order_roi', 'platform_page_view_count',
|
|
'web_commodity_page_view_count', 'from_follow_uv'))
|
|
'web_commodity_page_view_count', 'from_follow_uv'))
|
|
- # print(c)
|
|
|
|
if 'data' in c.keys() and len(c["data"]["list"]) > 0:
|
|
if 'data' in c.keys() and len(c["data"]["list"]) > 0:
|
|
for d in c['data']['list']:
|
|
for d in c['data']['list']:
|
|
d['account_id'] = y[0]
|
|
d['account_id'] = y[0]
|
|
- print(d['account_id'], d["cost"])
|
|
|
|
|
|
+ logging.info('qq: '+str(d['account_id'])+ str(d["cost"]))
|
|
x = tuple(d.values())
|
|
x = tuple(d.values())
|
|
li.append(x)
|
|
li.append(x)
|
|
|
|
|
|
-def get_v_data(y,li,st,et):
|
|
|
|
- c = daily_reports_get(y[2], y[0],st,et, "REPORT_LEVEL_ADVERTISER_WECHAT", (
|
|
|
|
|
|
+
|
|
|
|
+def get_v_data(y, li, st, et):
|
|
|
|
+ c = daily_reports_get(y[2], y[0], st, et, "REPORT_LEVEL_ADVERTISER_WECHAT", (
|
|
'date', 'cost', 'view_count', 'valid_click_count', 'ctr', 'official_account_follow_rate', 'order_amount',
|
|
'date', 'cost', 'view_count', 'valid_click_count', 'ctr', 'official_account_follow_rate', 'order_amount',
|
|
'order_roi', 'order_count', 'order_rate', 'order_unit_price', 'web_order_cost', 'first_day_order_amount',
|
|
'order_roi', 'order_count', 'order_rate', 'order_unit_price', 'web_order_cost', 'first_day_order_amount',
|
|
'first_day_order_count'))
|
|
'first_day_order_count'))
|
|
- # print(c)
|
|
|
|
|
|
|
|
- if 'data' in c.keys() and len(c["data"]["list"])>0:
|
|
|
|
|
|
+ if 'data' in c.keys() and len(c["data"]["list"]) > 0:
|
|
for d in c['data']['list']:
|
|
for d in c['data']['list']:
|
|
d['account_id'] = y[0]
|
|
d['account_id'] = y[0]
|
|
- print(d['account_id'], d["cost"])
|
|
|
|
|
|
+ logging.info('vx:'+str(d['account_id'])+ str(d["cost"]))
|
|
x = tuple(d.values())
|
|
x = tuple(d.values())
|
|
li.append(x)
|
|
li.append(x)
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
def get_vx_list():
|
|
def get_vx_list():
|
|
- sql="select account_id,wechat_account_id,access_token,refresh_token,name," \
|
|
|
|
- "ifnull(stage,''),ifnull(pitcher,''),ifnull(platform,''),ifnull(book,'') from advertiser_vx"
|
|
|
|
- a= db.quchen_text.getData(sql)
|
|
|
|
- return a
|
|
|
|
|
|
+ sql = "select account_id,wechat_account_id,access_token,refresh_token,name," \
|
|
|
|
+ "ifnull(stage,''),ifnull(pitcher,''),ifnull(platform,''),ifnull(book,'') from advertiser_vx"
|
|
|
|
+ a = db.quchen_text.getData(sql)
|
|
|
|
+ return a
|
|
|
|
+
|
|
|
|
|
|
def get_qq_list():
|
|
def get_qq_list():
|
|
- sql = "select account_id,'',access_token,refresh_token,name," \
|
|
|
|
- "ifnull(stage,''),ifnull(pitcher,''),ifnull(platform,''),ifnull(book,'') from advertiser_qq"
|
|
|
|
- a = db.quchen_text.getData(sql)
|
|
|
|
- return a
|
|
|
|
|
|
+ sql = "select account_id,'',access_token,refresh_token,name," \
|
|
|
|
+ "ifnull(stage,''),ifnull(pitcher,''),ifnull(platform,''),ifnull(book,'') from advertiser_qq"
|
|
|
|
+ a = db.quchen_text.getData(sql)
|
|
|
|
+ return a
|
|
|
|
|
|
|
|
|
|
-def get_daily_vx(st,et):
|
|
|
|
- token_list_v = get_vx_list()
|
|
|
|
- print("获取vx账号:",token_list_v.__len__())
|
|
|
|
|
|
+def get_daily_vx(st, et):
|
|
|
|
+ token_list_v = get_vx_list()
|
|
|
|
+ logging.info("获取vx账号:" + str(token_list_v.__len__()))
|
|
|
|
|
|
- time1 = time.time()
|
|
|
|
- executor = ThreadPoolExecutor(max_workers=10)
|
|
|
|
- li=[]
|
|
|
|
- for y in token_list_v:
|
|
|
|
- executor.submit(get_v_data,y,li,st,et)
|
|
|
|
- executor.shutdown()
|
|
|
|
- print('get_daily_vx:', len(li), 'cost:', int(time.time()-time1))
|
|
|
|
|
|
+ time1 = time.time()
|
|
|
|
+ executor = ThreadPoolExecutor(max_workers=10)
|
|
|
|
+ li = []
|
|
|
|
+ for y in token_list_v:
|
|
|
|
+ executor.submit(get_v_data, y, li, st, et)
|
|
|
|
+ executor.shutdown()
|
|
|
|
+ logging.info('get_daily_vx:' + str(len(li)) + 'cost:' + str(int(time.time() - time1)))
|
|
|
|
|
|
- mysql_insert_daily_vx(li)
|
|
|
|
|
|
+ mysql_insert_daily_vx(li)
|
|
|
|
|
|
-def get_daily_qq(st,et):
|
|
|
|
- token_list_q = get_qq_list()
|
|
|
|
- print("获取qq账号:",token_list_q.__len__())
|
|
|
|
- time1 = time.time()
|
|
|
|
- li=[]
|
|
|
|
- executor = ThreadPoolExecutor(max_workers=10)
|
|
|
|
- for x in token_list_q:
|
|
|
|
|
|
|
|
- executor.submit(get_q_data,x,li,st,et)
|
|
|
|
- executor.shutdown()
|
|
|
|
- print('get_qq_order:', len(li), 'cost:', int(time.time()-time1))
|
|
|
|
- mysql_insert_daily_qq(li)
|
|
|
|
|
|
+def get_daily_qq(st, et):
|
|
|
|
+ token_list_q = get_qq_list()
|
|
|
|
+ logging.info("获取qq账号:" + str(token_list_q.__len__()))
|
|
|
|
+ time1 = time.time()
|
|
|
|
+ li = []
|
|
|
|
+ executor = ThreadPoolExecutor(max_workers=10)
|
|
|
|
+ for x in token_list_q:
|
|
|
|
+ executor.submit(get_q_data, x, li, st, et)
|
|
|
|
+ executor.shutdown()
|
|
|
|
+ logging.info('get_qq_order:' + str(len(li)) + 'cost:' + str(int(time.time() - time1)))
|
|
|
|
+ mysql_insert_daily_qq(li)
|
|
|
|
|
|
|
|
|
|
def mysql_insert_daily_vx(data):
|
|
def mysql_insert_daily_vx(data):
|
|
-
|
|
|
|
- b ="""replace into daily_vx (date,cost,view_count,valid_click_count,ctr,official_account_follow_rate,order_amount,
|
|
|
|
|
|
+ b = """replace into daily_vx (date,cost,view_count,valid_click_count,ctr,official_account_follow_rate,order_amount,
|
|
order_roi,order_count,order_rate,order_unit_price,web_order_cost,first_day_order_amount,first_day_order_count,account_id)
|
|
order_roi,order_count,order_rate,order_unit_price,web_order_cost,first_day_order_amount,first_day_order_count,account_id)
|
|
values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
|
|
values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
|
|
db.quchen_text.executeMany(b, data)
|
|
db.quchen_text.executeMany(b, data)
|
|
@@ -140,32 +135,35 @@ def mysql_insert_daily_qq(data):
|
|
a = """replace into daily_qq (date,view_count,valid_click_count,ctr,cpc,cost,web_order_count,web_order_rate,
|
|
a = """replace into daily_qq (date,view_count,valid_click_count,ctr,cpc,cost,web_order_count,web_order_rate,
|
|
web_order_cost,follow_count,order_amount,order_roi,platform_page_view_count,web_commodity_page_view_count,
|
|
web_order_cost,follow_count,order_amount,order_roi,platform_page_view_count,web_commodity_page_view_count,
|
|
from_follow_uv,account_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
|
|
from_follow_uv,account_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
|
|
- db.quchen_text.executeMany(a,data)
|
|
|
|
|
|
+ db.quchen_text.executeMany(a, data)
|
|
|
|
|
|
|
|
|
|
-def run(st,et):
|
|
|
|
- get_daily_vx(st,et)
|
|
|
|
- get_daily_qq(st,et)
|
|
|
|
|
|
+def run(st, et):
|
|
|
|
+ logging.info('微信消耗数据拉取,开始')
|
|
|
|
+ get_daily_vx(st, et)
|
|
|
|
+ logging.info('微信消耗数据拉取,结束')
|
|
|
|
+ logging.info('qq消耗数据拉取,开始')
|
|
|
|
+ get_daily_qq(st, et)
|
|
|
|
+ logging.info('qq消耗数据拉取,结束')
|
|
|
|
+
|
|
|
|
|
|
def old_cost_hourly():
|
|
def old_cost_hourly():
|
|
- st = et =du.getNow()
|
|
|
|
|
|
+ st = et = du.getNow()
|
|
|
|
+ logging.info('消耗数据拉取,开始')
|
|
run(st, et)
|
|
run(st, et)
|
|
|
|
+ logging.info('消耗数据拉取,结束')
|
|
|
|
+
|
|
|
|
|
|
def old_cost_daily():
|
|
def old_cost_daily():
|
|
st = du.get_n_days(-10)
|
|
st = du.get_n_days(-10)
|
|
et = du.get_n_days(-1)
|
|
et = du.get_n_days(-1)
|
|
run(st, et)
|
|
run(st, et)
|
|
|
|
|
|
-if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
+if __name__ == '__main__':
|
|
# run()
|
|
# run()
|
|
# old_cost_daily()
|
|
# old_cost_daily()
|
|
st = du.get_n_days(-6)
|
|
st = du.get_n_days(-6)
|
|
et = du.get_n_days(-1)
|
|
et = du.get_n_days(-1)
|
|
- print(st,et)
|
|
|
|
|
|
+ print(st, et)
|
|
run(st, et)
|
|
run(st, et)
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|