sync_author_fq_mf.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 data = await require('../src/api/fq/fq_search_book').search_mf_new_id(video_product_info.product_id)
  29. if(data!=null){
  30. let author = data.author
  31. await connection.execute(
  32. ` UPDATE video_product SET author = '${author}' WHERE id = ${video_product_info.id} `
  33. );
  34. }else{
  35. await connection.execute(
  36. ` UPDATE video_product SET author = 'NONE' WHERE id = ${video_product_info.id} `
  37. );
  38. console.error("查无此书:",video_product_info)
  39. }
  40. }
  41. }catch(e){
  42. if(e==0){
  43. right_status = false
  44. }
  45. console.error("processTask error:",e)
  46. } finally{
  47. if(connection!=null){
  48. connection.end()
  49. }
  50. global.setTimeout(processTask, 1000);
  51. }
  52. }
  53. CMD.init = async function(){
  54. redis_help.connect((results)=>{
  55. if(results){
  56. processTask();
  57. }
  58. })
  59. }
  60. CMD.init()