sync_author_fq_mf.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers');
  7. const helper = require("../src/helper");
  8. const CMD = {}
  9. async function processTask(){
  10. let right_status = true
  11. let connection = null
  12. try{
  13. connection = await mysql.createConnection({
  14. ...taskdbConfig,
  15. multipleStatements: true
  16. });
  17. //先获取100本没有发布时间的番茄免费书籍
  18. let sql = `SELECT * FROM video_product WHERE book_platform = ${config.platform_fanqiemf} AND author IS NULL LIMIT 5`
  19. console.log("sql:",sql)
  20. const [rows] = await connection.execute(
  21. sql
  22. );
  23. if(rows.length<=0){
  24. throw 0
  25. }
  26. for (let index = 0; index < rows.length; index++) {
  27. let video_product_info = rows[index]
  28. let book_info = await video_product_controllers.getProductData({book_id:video_product_info.product_parent_id})
  29. if(book_info.success){
  30. let data = await require('../src/api/fq/fq_search_book').search_mf_new_id(video_product_info.product_parent_id)
  31. if(data!=null&&data!=""){
  32. let author = data.author
  33. await connection.execute(
  34. ` UPDATE video_product SET author = '${author}' WHERE id = ${video_product_info.id} `
  35. );
  36. }else{
  37. await connection.execute(
  38. ` UPDATE video_product SET author = 'NONE' WHERE id = ${video_product_info.id} `
  39. );
  40. console.error("查无此书:",video_product_info)
  41. }
  42. }
  43. }
  44. }catch(e){
  45. if(e==0){
  46. right_status = false
  47. }
  48. console.error("processTask error:",e)
  49. } finally{
  50. if(connection!=null){
  51. connection.end()
  52. }
  53. global.setTimeout(processTask, 2000);
  54. }
  55. }
  56. CMD.init = async function(){
  57. redis_help.connect((results)=>{
  58. if(results){
  59. processTask();
  60. }
  61. })
  62. }
  63. CMD.init()