youshuge.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. a = '趣程清勇6,10675,B6FK1HFW1V9ZPD6WX0FGBX3WP73E6M5V,璃月文楼,清勇7月'
  57. get_youshuge_order_task('2021-01-06', '2021-08-06', a.split(','))