youshuge.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import time
  2. from model.DateUtils import DateUtils
  3. from model.ComUtils import md5
  4. import requests
  5. from app.api_data.platform_order.order_util import save_order
  6. ut = DateUtils()
  7. def get_youshuge_order_task(st, et, account):
  8. et = ut.add_days(et,1)
  9. url = 'https://novel.youshuge.com/v2/open/orders'
  10. host_name = account[0]
  11. channel_id = int(account[1])
  12. secert_key = account[2]
  13. channel = account[3]
  14. stage = account[4]
  15. page = 1
  16. li = []
  17. while True:
  18. timestamp = int(time.time())
  19. sign = md5('channel_id=' + str(channel_id) + '&end_date=' + et + '&host_name=' + host_name + '&page='
  20. + str(page) + '&start_date=' + st + '&time=' + str(
  21. timestamp) + '&key=' + secert_key).upper()
  22. params = {
  23. 'sign': sign,
  24. 'host_name': host_name,
  25. 'time': timestamp,
  26. 'channel_id': channel_id,
  27. 'page': page,
  28. 'start_date': st,
  29. 'end_date': et
  30. }
  31. r = requests.post(url, params).json()
  32. # print(r)
  33. order_item_list = r['data']
  34. if len(order_item_list) == 0:
  35. break
  36. for i in order_item_list:
  37. li.append((i["create_time"][:10],
  38. stage,
  39. '悠书阁',
  40. channel,
  41. channel_id,
  42. i['openid'],
  43. i["create_time"],
  44. i['reg_time'],
  45. int(i['price'])/100,
  46. i['book_name'],
  47. i['order_num'],
  48. 2 if i['pay_status'] == '1' else 1
  49. ))
  50. page += 1
  51. if len(li) > 0:
  52. print(f"{channel} 有订单{len(li)}")
  53. save_order(li)
  54. if __name__ == '__main__':
  55. a = "趣程15期,10696,8OC7SNCL46ZEI7JBACXFDM8CP5JM1FSL,盛德文苑,趣程15期"
  56. get_youshuge_order_task('2021-01-06', '2021-05-06', a.split(','))