youshuge.py 2.0 KB

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