904118851 3 tháng trước cách đây
mục cha
commit
12c9e84253

+ 1 - 0
src/api/qm/qm_search_book.js

@@ -26,6 +26,7 @@ CMD.search_id = async function (bookId) {
         info.words =  Math.floor(parseFloat(book_info.wordCount)*10000)
         info.book_name =  book_info.title
         info.book_id =  book_info.id
+        info.publish_time = book_info.addTime
         if(book_info.type="短篇"){
             info.genre = 3;
         }else{

+ 82 - 44
src/api/qm_mf/qm_mf_search_book.js

@@ -1,62 +1,100 @@
 const fetch = require('node-fetch'); // Node.js 18以下版本需要安装 node-fetch
 const tools = require('../../../tools');
 const helper = require('../../helper');
+const mysql = require('mysql2/promise');
+const config = require("../../../etc/config.json");
+const dbConfig = config.isDebug?config.debug_mysql:config.release_mysql
 const CMD = {}
 CMD.search_id = async function (bookId) {
-    const url = 'https://new-media-iaa-fx.qimao.com/api/content/book/list';
-    
-    // 请求参数
-    const params = new URLSearchParams({
-        book_id: bookId,
-        page: '1',
-        page_size: '50',
-        env: '',
-        t: Date.now()  // 当前时间戳
-    });
+    let connection  = null
+    try{
+        connection = await mysql.createConnection({
+                ...dbConfig,
+                multipleStatements: true
+            });
+        let sql = `SELECT * FROM book_iaa_info WHERE id = ${bookId} LIMIT 1`
+        const [rows] = await connection.execute(
+            sql
+        );
 
-    // 请求头
-    var headers = {
-        'accept': 'application/json, text/plain, */*',
-        "app-id": "ttaeafd812319b128201",
-        'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBY2NvdW50SUQiOjU1NzcwMjIxODI2MzQ0OTYxMSwiQWNjb3VudE5hbWUiOiJ6aHVveXVlIiwiVGltZVN0YW1wIjoxNzQyMjgwNDU1LCJDbGllbnRJUCI6IjIxOS4xMzYuMTMwLjEwNyIsIkJ1ZmZlclRpbWUiOjAsImV4cCI6MTc0MjM2Njg1NSwiaXNzIjoicW1fbmV3X21lZGlhX2Z4IiwibmJmIjoxNzQyMjgwNDU1LCJFbnYiOiJyZWxlYXNlIiwiSXNTaW11bGF0aW9uTG9naW4iOmZhbHNlfQ.nUn5QkVnC-oQ6qwjc8Bh5jRTsTKqwzPS5cphBIiaBvU',
-        'project': 'reader_free_dyminiapp',
-        'signature': '27f1c6bd848f65d15f3454b05872b789b1b8357f16ea2d2aead044780d371e11',
-        'target-id': '558102575356793781'
-    };
-
-    headers['authorization'] = await tools.getQMMFToken()
-    try {
-        const response = await fetch(`${url}?${params}`, {
-            method: 'GET',
-            headers: headers
-        });
-
-        const data = await response.json();
-
-        if(data.code!=200){
-            throw data
-        }
-        // console.log('响应状态:', response.status);
-        // console.log('响应数据:', data.data.list[0]);
-        if(data.data.list.length<=0){
-            return null
+        if(rows.length<=0){
+            throw 0
         }
-        let book_info = data.data.list[0]
-        console.error("data:",data.data.list[0])
+        let book_info = rows[0]
         let info = {}
-        info.words =  Math.floor(parseFloat(book_info.book_word_count)*10000)
-        info.book_name =  book_info.book_name
-        info.book_id =  book_info.book_id
-        info.genre = 999;
-        if(book_info.book_type==2){  //七猫只有长或者短
+        info.words =  Math.floor(parseFloat(book_info.wordCount)*10000)
+        info.book_name =  book_info.title
+        info.book_id =  book_info.id
+        info.publish_time = book_info.addTime
+        if(book_info.type="短篇"){
             info.genre = 3;
         }else{
             info.genre = 1;
         }
         return info;
-    } catch (error) {
+
+    }catch(e){
+        console.error(e)
         return null
+    }finally{
+        if(connection!=null){
+            connection.end()
+        }
     }
+    // const url = 'https://new-media-iaa-fx.qimao.com/api/content/book/list';
+    
+    // // 请求参数
+    // const params = new URLSearchParams({
+    //     book_id: bookId,
+    //     page: '1',
+    //     page_size: '50',
+    //     env: '',
+    //     t: Date.now()  // 当前时间戳
+    // });
+
+    // // 请求头
+    // var headers = {
+    //     'accept': 'application/json, text/plain, */*',
+    //     "app-id": "ttaeafd812319b128201",
+    //     'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBY2NvdW50SUQiOjU1NzcwMjIxODI2MzQ0OTYxMSwiQWNjb3VudE5hbWUiOiJ6aHVveXVlIiwiVGltZVN0YW1wIjoxNzQyMjgwNDU1LCJDbGllbnRJUCI6IjIxOS4xMzYuMTMwLjEwNyIsIkJ1ZmZlclRpbWUiOjAsImV4cCI6MTc0MjM2Njg1NSwiaXNzIjoicW1fbmV3X21lZGlhX2Z4IiwibmJmIjoxNzQyMjgwNDU1LCJFbnYiOiJyZWxlYXNlIiwiSXNTaW11bGF0aW9uTG9naW4iOmZhbHNlfQ.nUn5QkVnC-oQ6qwjc8Bh5jRTsTKqwzPS5cphBIiaBvU',
+    //     'project': 'reader_free_dyminiapp',
+    //     'signature': '27f1c6bd848f65d15f3454b05872b789b1b8357f16ea2d2aead044780d371e11',
+    //     'target-id': '558102575356793781'
+    // };
+
+    // headers['authorization'] = await tools.getQMMFToken()
+    // try {
+    //     const response = await fetch(`${url}?${params}`, {
+    //         method: 'GET',
+    //         headers: headers
+    //     });
+
+    //     const data = await response.json();
+
+    //     if(data.code!=200){
+    //         throw data
+    //     }
+    //     // console.log('响应状态:', response.status);
+    //     // console.log('响应数据:', data.data.list[0]);
+    //     if(data.data.list.length<=0){
+    //         return null
+    //     }
+    //     let book_info = data.data.list[0]
+    //     console.error("data:",data.data.list[0])
+    //     let info = {}
+    //     info.words =  Math.floor(parseFloat(book_info.book_word_count)*10000)
+    //     info.book_name =  book_info.book_name
+    //     info.book_id =  book_info.book_id
+    //     info.genre = 999;
+    //     if(book_info.book_type==2){  //七猫只有长或者短
+    //         info.genre = 3;
+    //     }else{
+    //         info.genre = 1;
+    //     }
+    //     return info;
+    // } catch (error) {
+    //     return null
+    // }
 }
 
 CMD.search_name = async function (book_author,origin_book_name) {

+ 14 - 0
task_script.json

@@ -98,6 +98,20 @@
             "exec_mode": "fork",
             "autorestart": true
         },
+        {
+            "name": "sync_publish_time_qm_mf",
+            "script": "./task_script/sync_publish_time_qm_mf.js",
+            "node_args": "--max-old-space-size=8192 --expose-gc",
+            "max_memory_restart": "4G",
+            "args": ["--type=data"],
+            "cwd": "/home/tg_factory",
+            "log_date_format": "YYYY-MM-DD HH:mm:ss",
+            "error_file": "./logs/task_script/sync_publish_time_qm_mf_error.log",
+            "out_file": "./logs/task_script/sync_publish_time_qm_mf_out.log",
+            "merge_logs": true,
+            "exec_mode": "fork",
+            "autorestart": true
+        },
         {
             "name": "sync_publish_time_yw",
             "script": "./task_script/sync_publish_time_yw.js",

+ 68 - 0
task_script/sync_publish_time_qm_mf.js

@@ -0,0 +1,68 @@
+//同步七猫免费的发布时间
+const config = require("../etc/config.json");
+const mysql = require('mysql2/promise');
+const taskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_mysql
+const redis_help = require('../src/use_redis');
+const CMD = {}
+async function processTask(){
+    let right_status = true
+    let connection  = null
+    try{
+        connection = await mysql.createConnection({
+            ...taskdbConfig,
+            multipleStatements: true
+        });
+        //先获取100本没有发布时间的七猫免费书籍
+        let sql = `SELECT * FROM video_product WHERE book_platform = ${config.platform_qmmf} AND  publish_time IS NULL  LIMIT 500`
+        console.log("sql:",sql)
+        const [rows] = await connection.execute(
+            sql
+        );
+
+        if(rows.length<=0){
+            throw 0
+        }
+
+        for (let index = 0; index < rows.length; index++) {
+            let video_product_info = rows[index]
+           
+            let data =  await require('../src/api/qm_mf/qm_mf_search_book').search_id(video_product_info.product_id)
+            if(data!=null){
+                let publish_time = data.publish_time
+                await connection.execute(
+                    `UPDATE video_product SET publish_time = "${publish_time}"  WHERE id = ${video_product_info.id} `
+                );
+            }else{
+                await connection.execute(
+                    ` UPDATE video_product SET status = 0 , publish_time = '2000-01-01 01:01:01' WHERE id = ${video_product_info.id}  `
+                );
+            }
+        }
+
+
+    }catch(e){
+        if(e==0){
+            right_status = false
+        }
+        console.error("processTask error:",e)
+    } finally{
+        if(connection!=null){
+            connection.end()
+        }
+        global.setTimeout(processTask, 2000);
+    }
+
+}
+
+
+
+CMD.init = async function(){
+    redis_help.connect((results)=>{
+        if(results){
+            processTask();
+        }
+    })
+
+}
+
+CMD.init()