sync_publish_time_yw.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //同步阅文的发布时间
  2. const config = require("../etc/config.json");
  3. const mysql = require('mysql2/promise');
  4. const taskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_mysql
  5. const redis_help = require('../src/use_redis');
  6. const CMD = {}
  7. async function processTask(){
  8. let right_status = true
  9. let connection = null
  10. try{
  11. connection = await mysql.createConnection({
  12. ...taskdbConfig,
  13. multipleStatements: true
  14. });
  15. //先获取100本没有发布时间的阅文书籍
  16. let sql = `SELECT * FROM video_product WHERE book_platform = ${config.platform_yuewen} AND publish_time IS NULL LIMIT 500`
  17. console.log("sql:",sql)
  18. const [rows] = await connection.execute(
  19. sql
  20. );
  21. if(rows.length<=0){
  22. throw 0
  23. }
  24. for (let index = 0; index < rows.length; index++) {
  25. let video_product_info = rows[index]
  26. let data = await require('../src/api/yw/get_book_tg_chapter_id').get_book_publish_time(video_product_info.product_id)
  27. if(data!=null){
  28. let publish_time = data.CheckTime
  29. await connection.execute(
  30. `UPDATE video_product SET publish_time = "${publish_time}" WHERE id = ${video_product_info.id} `
  31. );
  32. }else{
  33. await connection.execute(
  34. ` UPDATE video_product SET status = 0 , publish_time = '2000-01-01 01:01:01' WHERE id = ${video_product_info.id} `
  35. );
  36. console.error("查无此书:",video_product_info)
  37. }
  38. }
  39. }catch(e){
  40. if(e==0){
  41. right_status = false
  42. }
  43. console.error("processTask error:",e)
  44. } finally{
  45. if(connection!=null){
  46. connection.end()
  47. }
  48. global.setTimeout(processTask, 2000);
  49. }
  50. }
  51. CMD.init = async function(){
  52. redis_help.connect((results)=>{
  53. if(results){
  54. processTask();
  55. }
  56. })
  57. }
  58. CMD.init()