import time from model.ComUtils import md5, split_int import json from model.DateUtils import DateUtils from model.DataBaseUtils import MysqlUtils import requests from app.api_data.platform_order.order_util import save_order ut = DateUtils() db = MysqlUtils() def get_all_channel(): sql = ''' select name,wechat_account_id from advertiser_vx av ''' vx_list = db.quchen_text.get_data_list(sql) res = {} for channel, account_id in vx_list: res[account_id] = channel return res def get_wandu_order(st, et, account, channel_info): print('get in ') baseurl = 'http://vipzeus.666shuwu.cn/api/vipoutput/getorder' api_secret, uid, stage = account print(account) start_time = DateUtils.str_to_stamp(st) # 结束时间不能超过当前的时间戳 if et == ut.getNow(): end_time = DateUtils.str_to_stamp(ut.get_n_minutes_ago(), "%Y-%m-%d %H:%M:%S") else: end_time = DateUtils.str_to_stamp(et) + 86399 params = {} page = 1 li = [] while True: # 时间 params['starttime'] = start_time params['endtime'] = end_time # 基础信息 params['uid'] = uid timestamp = int(time.time()) params['timestamp'] = timestamp sign = md5(uid + api_secret + str(timestamp)) print(sign) params['sign'] = sign params['page'] = page rsp = requests.get(baseurl, params=params) print(rsp.text) print(json.dumps(rsp.json(), ensure_ascii=False)) print(rsp.text) rsp_json = rsp.json() page = int(rsp_json['data']['page']) page_size = int(rsp_json['data']['count_page']) # 存入数据 rsp_info = rsp_json['data']['list'] for _ in rsp_info: struct_time = time.localtime(_['ctime']) # 得到结构化时间格式 order_time = time.strftime("%Y-%m-%d", struct_time) order_time_detail = time.strftime('%Y-%m-%d %H:%M:%S', struct_time) struct_time_reg = time.localtime(_['regtime']) # 得到结构化时间格式 reg_time_detail = time.strftime('%Y-%m-%d %H:%M:%S', struct_time_reg) # print(_['status'],type(_['status'])) order_status = 2 if _['status'] == 3 else 1 li.append((order_time, stage, '万读', channel_info[_['appid']], 0, _['openid'], order_time_detail, reg_time_detail, _['amount'], '', _['orderno'], order_status )) # 外出 if page > page_size or page == page_size: break page = page + 1 save_order(li) if __name__ == '__main__': channel_info = get_all_channel() get_wandu_order('2019-08-01', '2021-10-20', '7ffedfa36431ca09c231bbdc8ca12217,6121,趣程43期', channel_info) # get_yuewen_order_task('2021-08-01', '2021-08-02', a.split(','))