wandu.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import time
  2. from model.ComUtils import md5, split_int
  3. import json
  4. from model.DateUtils import DateUtils
  5. from model.DataBaseUtils import MysqlUtils
  6. import requests
  7. from app.api_data.platform_order.order_util import save_order
  8. ut = DateUtils()
  9. db = MysqlUtils()
  10. def get_all_channel():
  11. sql = '''
  12. select name,wechat_account_id from advertiser_vx av
  13. '''
  14. vx_list = db.quchen_text.get_data_list(sql)
  15. res = {}
  16. for channel, account_id in vx_list:
  17. res[account_id] = channel
  18. return res
  19. def get_wandu_order(st, et, account, channel_info):
  20. print('get in ')
  21. baseurl = 'http://vipzeus.666shuwu.cn/api/vipoutput/getorder'
  22. api_secret, uid, stage = account
  23. print(account)
  24. start_time = DateUtils.str_to_stamp(st)
  25. # 结束时间不能超过当前的时间戳
  26. if et == ut.getNow():
  27. end_time = DateUtils.str_to_stamp(ut.get_n_minutes_ago(), "%Y-%m-%d %H:%M:%S")
  28. else:
  29. end_time = DateUtils.str_to_stamp(et) + 86399
  30. params = {}
  31. page = 1
  32. li = []
  33. while True:
  34. # 时间
  35. params['starttime'] = start_time
  36. params['endtime'] = end_time
  37. # 基础信息
  38. params['uid'] = uid
  39. timestamp = int(time.time())
  40. params['timestamp'] = timestamp
  41. sign = md5(uid + api_secret + str(timestamp))
  42. print(sign)
  43. params['sign'] = sign
  44. params['page'] = page
  45. rsp = requests.get(baseurl, params=params)
  46. print(rsp.text)
  47. print(json.dumps(rsp.json(), ensure_ascii=False))
  48. print(rsp.text)
  49. rsp_json = rsp.json()
  50. page = int(rsp_json['data']['page'])
  51. page_size = int(rsp_json['data']['count_page'])
  52. # 存入数据
  53. rsp_info = rsp_json['data']['list']
  54. for _ in rsp_info:
  55. struct_time = time.localtime(_['ctime']) # 得到结构化时间格式
  56. order_time = time.strftime("%Y-%m-%d", struct_time)
  57. order_time_detail = time.strftime('%Y-%m-%d %H:%M:%S', struct_time)
  58. struct_time_reg = time.localtime(_['regtime']) # 得到结构化时间格式
  59. reg_time_detail = time.strftime('%Y-%m-%d %H:%M:%S', struct_time_reg)
  60. # print(_['status'],type(_['status']))
  61. order_status = 2 if _['status'] == 3 else 1
  62. li.append((order_time,
  63. stage,
  64. '万读',
  65. channel_info[_['appid']],
  66. 0,
  67. _['openid'],
  68. order_time_detail,
  69. reg_time_detail,
  70. _['amount'],
  71. '',
  72. _['orderno'],
  73. order_status
  74. ))
  75. # 外出
  76. if page > page_size or page == page_size:
  77. break
  78. page = page + 1
  79. save_order(li)
  80. if __name__ == '__main__':
  81. channel_info = get_all_channel()
  82. get_wandu_order('2019-08-01', '2021-10-20', '7ffedfa36431ca09c231bbdc8ca12217,6121,趣程43期', channel_info)
  83. # get_yuewen_order_task('2021-08-01', '2021-08-02', a.split(','))