|
@@ -1,16 +1,16 @@
|
|
|
from model.DataBaseUtils import MysqlUtils
|
|
|
-from model.DingTalkUtils import DingTalkDecorators,DingTalkUtils
|
|
|
+from model.DingTalkUtils import DingTalkDecorators, DingTalkUtils
|
|
|
from model.DateUtils import DateUtils
|
|
|
from model import ComUtils
|
|
|
import time
|
|
|
import json
|
|
|
import requests
|
|
|
+
|
|
|
db = MysqlUtils()
|
|
|
du = DateUtils()
|
|
|
|
|
|
|
|
|
-
|
|
|
-@DingTalkDecorators("阳光")
|
|
|
+# @DingTalkDecorators("阳光")
|
|
|
def yangguang(start=None, end=None):
|
|
|
accounts = get_account("阳光")
|
|
|
|
|
@@ -32,7 +32,7 @@ def yangguang(start=None, end=None):
|
|
|
for i in accounts:
|
|
|
stage = i[0]
|
|
|
vip_id = i[1]
|
|
|
- print(stage,vip_id)
|
|
|
+ print(stage, vip_id)
|
|
|
print(vip_id)
|
|
|
# get_yg_vip_channel(stage, vip_id, client_id, token)
|
|
|
get_yg_data(stage, vip_id, client_id, token, start, end)
|
|
@@ -40,11 +40,12 @@ def yangguang(start=None, end=None):
|
|
|
print(check())
|
|
|
parse_order_data()
|
|
|
|
|
|
-def get_yg_data(stage,vip_id,client_id,token,start,end):
|
|
|
+
|
|
|
+def get_yg_data(stage, vip_id, client_id, token, start, end):
|
|
|
url = "https://data.yifengaf.cn:443/channeldata/data/orders/list"
|
|
|
- nonce=ComUtils.get_random_str()
|
|
|
- timestamp=int(time.time())
|
|
|
- signaure =ComUtils.sha1(str(token) + str(timestamp) + str(client_id) + str(nonce))
|
|
|
+ nonce = ComUtils.get_random_str()
|
|
|
+ timestamp = int(time.time())
|
|
|
+ signaure = ComUtils.sha1(str(token) + str(timestamp) + str(client_id) + str(nonce))
|
|
|
params = {
|
|
|
"client_id": client_id,
|
|
|
"token": token,
|
|
@@ -52,20 +53,21 @@ def get_yg_data(stage,vip_id,client_id,token,start,end):
|
|
|
"timestamp": timestamp,
|
|
|
"signaure": signaure,
|
|
|
"vip_id": vip_id,
|
|
|
- "start_time":start, # %Y-%m-%d %H:%i:%s:
|
|
|
- "end_time":end
|
|
|
+ "start_time": start, # %Y-%m-%d %H:%i:%s:
|
|
|
+ "end_time": end
|
|
|
}
|
|
|
- headers={"Content-Type":"application/json"}
|
|
|
+ headers = {"Content-Type": "application/json"}
|
|
|
for i in range(5):
|
|
|
try:
|
|
|
- r=requests.post(url=url,data=json.dumps(params),headers=headers,timeout=5)
|
|
|
+ r = requests.post(url=url, data=json.dumps(params), headers=headers, timeout=5)
|
|
|
break
|
|
|
except:
|
|
|
pass
|
|
|
raise
|
|
|
- print(vip_id,r.text)
|
|
|
+ print(vip_id, r.text)
|
|
|
task_id = json.loads(r.text).get("data").get("task_id")
|
|
|
- db.quchen_text.execute(f"replace into yangguang_path(vip_id,task_id,stage,type) values ('{vip_id}','{task_id}','{stage}','order')")
|
|
|
+ db.quchen_text.execute(
|
|
|
+ f"replace into yangguang_path(vip_id,task_id,stage,type) values ('{vip_id}','{task_id}','{stage}','order')")
|
|
|
|
|
|
|
|
|
def get_yg_vip_channel(stage, vip_id, client_id, token):
|
|
@@ -106,53 +108,58 @@ def parse_order_data():
|
|
|
|
|
|
for i in accounts:
|
|
|
# print(i)
|
|
|
- vip_id = i[1]
|
|
|
- stage = i[0]
|
|
|
- data = parse_order(vip_id, stage)
|
|
|
- save_data(data)
|
|
|
+ try:
|
|
|
+ vip_id = i[1]
|
|
|
+ stage = i[0]
|
|
|
+ data = parse_order(vip_id, stage)
|
|
|
+ save_data(data)
|
|
|
+ except Exception as e:
|
|
|
+ DingTalkUtils.send('阳光出错vipid:' + vip_id, phone='15168342316')
|
|
|
+ print(e)
|
|
|
|
|
|
-def parse_order(vip_id,stage):
|
|
|
+
|
|
|
+def parse_order(vip_id, stage):
|
|
|
print(vip_id)
|
|
|
url = db.quchen_text.getOne(f"select path from yangguang_path where type='channel' and vip_id={vip_id} ")
|
|
|
for i in range(5):
|
|
|
try:
|
|
|
- r = requests.get(url,timeout=5).text
|
|
|
+ r = requests.get(url, timeout=5).text
|
|
|
break
|
|
|
except:
|
|
|
pass
|
|
|
raise
|
|
|
|
|
|
- channel_di={}
|
|
|
+ channel_di = {}
|
|
|
a = r.split('}')
|
|
|
for i in a[:-1]:
|
|
|
if i[-1] != '}':
|
|
|
- b=json.loads(i + "}", strict=False)
|
|
|
+ b = json.loads(i + "}", strict=False)
|
|
|
|
|
|
else:
|
|
|
- b=json.loads(i, strict=False)
|
|
|
- channel_di[b["channel_id"]]=(b["wx_nickname"],b['app_id'])
|
|
|
+ b = json.loads(i, strict=False)
|
|
|
+ channel_di[b["channel_id"]] = (b["wx_nickname"], b['app_id'])
|
|
|
|
|
|
# print(channel_di)
|
|
|
print(f'{stage} 有channel数:{len(channel_di)}')
|
|
|
|
|
|
- info=db.quchen_text.getData(f"select stage,path from yangguang_path where type='order' and vip_id={vip_id}")
|
|
|
- stage=info[0][0]
|
|
|
- path=info[0][1]
|
|
|
+ info = db.quchen_text.getData(f"select stage,path from yangguang_path where type='order' and vip_id={vip_id}")
|
|
|
+ stage = info[0][0]
|
|
|
+ path = info[0][1]
|
|
|
for i in range(5):
|
|
|
try:
|
|
|
- text=requests.get(path,timeout=5).text.replace('"referral_url":,','')
|
|
|
+ text = requests.get(path, timeout=5).text.replace('"referral_url":,', '')
|
|
|
# print(text)
|
|
|
break
|
|
|
- except:
|
|
|
- pass
|
|
|
- raise
|
|
|
+ except Exception as e:
|
|
|
+ print('channel', e)
|
|
|
+ # raise
|
|
|
|
|
|
- insert_data=[]
|
|
|
+ insert_data = []
|
|
|
for j in text.split("}")[:-1]:
|
|
|
if j[-1] != '}':
|
|
|
- j=j+'}'
|
|
|
+ j = j + '}'
|
|
|
try:
|
|
|
- di=json.loads(j, strict=False)
|
|
|
+ di = json.loads(j, strict=False)
|
|
|
except Exception as e:
|
|
|
print(j)
|
|
|
print(e)
|
|
@@ -169,7 +176,7 @@ def parse_order(vip_id,stage):
|
|
|
di['money'],
|
|
|
di.get('book_name'),
|
|
|
di['merchant_id'],
|
|
|
- 2 if di['state']=="完成" else 1,
|
|
|
+ 2 if di['state'] == "完成" else 1,
|
|
|
di['user_id'],
|
|
|
channel_di[di['channel_id']][1],
|
|
|
1 if di['type'] == '书币充值' else 2,
|
|
@@ -178,7 +185,7 @@ def parse_order(vip_id,stage):
|
|
|
))
|
|
|
# print(insert_data)
|
|
|
# exit(0)
|
|
|
- print("订单数:"+ str(insert_data.__len__()))
|
|
|
+ print("订单数:" + str(insert_data.__len__()))
|
|
|
save_data(insert_data)
|
|
|
|
|
|
|
|
@@ -188,11 +195,10 @@ def save_data(data):
|
|
|
trade_no,transaction_no) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) """
|
|
|
# print(sql)
|
|
|
|
|
|
- db.quchen_text.executeMany(sql,data)
|
|
|
+ db.quchen_text.executeMany(sql, data)
|
|
|
|
|
|
|
|
|
def check():
|
|
|
-
|
|
|
x = 1
|
|
|
while True:
|
|
|
a = db.quchen_text.getOne("select count(1) from yangguang_path where type ='order' and path is null")
|
|
@@ -217,6 +223,7 @@ def get_account(plactform, id=None):
|
|
|
new_data.append(i[0].replace('\n', '').split(","))
|
|
|
return new_data
|
|
|
|
|
|
+
|
|
|
def get_yg_user_info():
|
|
|
"""获取阳光的用户信息"""
|
|
|
accounts = get_account("阳光")
|
|
@@ -246,23 +253,16 @@ def get_yg_user_info():
|
|
|
# parse_data()
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
def daily_yg():
|
|
|
st = du.get_n_days(-10)
|
|
|
et = du.get_n_days(-1)
|
|
|
yangguang(st, et)
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
if __name__ == '__main__':
|
|
|
-
|
|
|
# get_channel_info()
|
|
|
# exit(0)
|
|
|
- yangguang(start=du.get_n_days(-1),end=du.get_n_days(0))
|
|
|
+ yangguang(start=du.get_n_days(-1), end=du.get_n_days(0))
|
|
|
# # exit(0)
|
|
|
# yangguang('2021-05-28','2021-05-28')
|
|
|
# daily_yg()
|