904118851 5 tháng trước cách đây
mục cha
commit
21dc4eef18
6 tập tin đã thay đổi với 116 bổ sung160 xóa
  1. 28 160
      qm_mf_book_async.js
  2. 10 0
      run_task_script.sh
  3. BIN
      src/api/hy/qr.gif
  4. BIN
      src/api/hy/qr_resized.gif
  5. 60 0
      src/api/qm_mf/qm_mf_search_book.js
  6. 18 0
      task_script.json

+ 28 - 160
qm_mf_book_async.js

@@ -16,10 +16,11 @@ function getCodeFromUrl(url) {
 }
 async function processTask(){
     let connection  = null
+    let status = 0
     try{
         const today = helper.getLocalDate();
         let date = today.replace(/-/g, '');
-        let table_name = `video_product`;
+        let table_name = `qm_iap_lib`;
         // 创建数据库连接
         connection = await mysql.createConnection({
             ...dbConfig,
@@ -40,178 +41,45 @@ async function processTask(){
             throw new Error(`表 ${table_name} 不存在`);
         } else {
             const [rows] = await connection.execute(
-                `SELECT * FROM ${table_name} WHERE book_platform = 3  LIMIT 6498`
+                `SELECT * FROM ${table_name} WHERE is_have_iaa = -1  LIMIT 100`
             );
     
             if(rows.length<=0){
-                throw "没有数据处理!"
+                throw -1
+            }
+            for (let index = 0; index < rows.length; index++) {
+                const element = rows[index];
+                let iaa_book_info = await require('./src/api/qm_mf/qm_mf_search_book').search_name(element.book_author,element.book_origin_name)
+                if(iaa_book_info!=null){
+                    await connection.execute(
+                        `UPDATE ${table_name} SET is_have_iaa = 1 , iaa_book_id = ${iaa_book_info.book_id}  WHERE book_id = ${element.book_id}`
+                    );    
+                }else{
+                    await connection.execute(
+                        `UPDATE ${table_name} SET is_have_iaa = 0  WHERE book_id = ${element.book_id}`
+                    );        
+                }
             }
-
-
-    
-        //     let id_list = []
-    
-        //     let video_id_list = []
-        //     let video_data_list = []
-            // rows.forEach((row, index) => {
-            //     id_list.push(row.id)
-            //     video_id_list.push(row.video_id)
-            //     video_data_list[row.video_id] = row
-            // });
-    
-        //     const [filter_rows] = await connection.execute(
-        //         `SELECT * FROM filter_data WHERE video_id IN (${video_id_list.join(",")})`
-        //     );
-
-        //     function getFilterById(video_id){
-        //         for (let index = 0; index < filter_rows.length; index++) {
-        //             const element = filter_rows[index];
-        //             if(element.video_id==video_id){
-        //                 return element
-        //             }
-        //         }
-        //         return null
-        //     }
-    
-        //     let need_insert_list  = []
-
-        //     for (let index = 0; index < video_id_list.length; index++) {
-        //         const video_id = video_id_list[index];
-        //         let d = getFilterById(video_id)
-        //         if(d==null){
-        //             need_insert_list.push(video_data_list[video_id])
-        //         }
-        //     }
-
-        //     let client =  new HttpClient()
-        //     let values = []
-
-        //     let sid_tt_status = true
-        //     for (let index = 0; index < need_insert_list.length; index++) {
-        //         const row = need_insert_list[index];
-        //         if(helper.checkChannel(row.guajian_link,"pages/theatre/index")){
-        //             let key =  getCodeFromUrl(row.guajian_link)
-        //             let book_name =  ""
-        //             let book_id = ""
-        //             if(key!=null){
-           
-        //                 let fq_book_result = await get_fq_book_tab_controllers.getData({ book_id: key });
-        //                 if(fq_book_result.success){
-        //                     book_name =  JSON.parse(fq_book_result.data.info.info).book_name
-        //                     book_id = fq_book_result.data.book_id
-        //                 }else{
-        //                     let sid_tt = await tools.getFqSidtt()
-        //                     let {url,params,headers}  = helper.getFqRequestOpt(key,sid_tt)
-        //                     let response = await client.fqProxyGet(url, params,headers)
-        
-                            
-        //                     if(response.code==0){
-        //                         let obj = response['data']
-
-        //                         book_name =  obj['video_info'].book_name
-        //                         book_id = obj['video_info'].book_id
-        
-        //                         let fq_book = {} 
-        //                         fq_book.key = key
-        //                         let fq_book_data = {book_name:book_name,book_id:book_id,info:JSON.stringify(obj['video_info'])}
-        //                         await CMD.add_fq_book(fq_book,fq_book_data)
-        //                     }else{
-        //                         if(response==""){
-        //                             sid_tt_status = false
-        //                         }
-        //                         console.log("error response:",response)
-        //                     }
-        //                 }
-                    
-        //             }else{
-        //                 console.log("key = null:",row.guajian_link)
-        //             }
-                  
-        //             if(book_name!=""){
-        //                 values.push({video_id:row.video_id,
-        //                     video_link:row.video_link,
-        //                     title:row.title,
-        //                     book_name:book_name,
-        //                     book_id:book_id,
-        //                     tg_platform_id:config.platform_fanqie_dx,
-        //                     like_num:row.like_num,
-        //                     comment_num:row.comment_num,
-        //                     shared_num:row.shared_num,
-        //                     kepp_num:row.kepp_num,
-        //                     create_time:new Date(),
-        //                     create_day:date,
-        //                     status:0,
-        //                     data_source:2
-        //                 })
-        //             }
-        //         }
-        //     }
-        //    console.log("values:",values)
-          
-        //     if(values.length>0&&sid_tt_status){
-
-        //         const formattedValues = values.map(item => [
-        //             item.video_id,
-        //             item.video_link,
-        //             item.title,
-        //             item.book_name,
-        //             item.book_id,
-        //             item.tg_platform_id,
-        //             item.like_num,
-        //             item.comment_num,
-        //             item.shared_num,
-        //             item.kepp_num,
-        //             item.create_time,
-        //             item.create_day,
-        //             item.status,
-        //             item.data_source
-        //         ]);
-        //         // 插入数据
-        //         const insertSQL = `
-        //         INSERT IGNORE INTO filter_data
-        //         (video_id, video_link, title, book_name, 
-        //         book_id, tg_platform_id, like_num, comment_num, shared_num,
-        //         kepp_num, create_time, create_day, status,data_source)
-        //         VALUES ?
-        //         `;
-                
-        //         await connection.query(insertSQL, [formattedValues]);
-        //     }
-
-    
-        //     const updateSQL = `
-        //     UPDATE xs_origin_data 
-        //     SET sync_info_status = 1
-        //     WHERE FIND_IN_SET(id, ?)
-        //     `;
-        
-        //     await connection.query(updateSQL, [id_list.join(',')]);
         }
         
     }catch(e){
+        if(e==-1){
+            status = -1
+        }
         console.error("processTask error:",e)
     } finally{
-        global.setTimeout(processTask, 1000);
-        // if(connection!=null){
-        //     await connection.end();
-        // }
+        if(status!=-1){
+            global.setTimeout(processTask, 1000);
+        }else{
+            console.log("完成所有定义!")
+        }
+        if(connection!=null){
+            await connection.end();
+        }
     }
 
 }
 
-CMD.add_fq_book = async function(data,response){
-    let book_name =  response.book_name
-    let book_id = response.book_id
-
-    data.book_name = book_name
-    data.book_id = book_id
-    let tab = {
-        book_key:data.key,
-        book_id:data.book_id,
-        info:JSON.stringify(response)
-    }
-    return await get_fq_book_tab_controllers.createData( tab)
-}
 
 CMD.init = async function(){
     redis_help.connect((results)=>{

+ 10 - 0
run_task_script.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+cd /home/tg_factory
+mkdir -p logs
+chmod 755 logs
+
+sleep 1
+/home/node/node-v20.17.0-linux-x64/lib/node_modules/pm2/bin/pm2 start task_script.json
+
+# sleep 1
+# bash /home/tg_factory/MESSAGE_DISPATCH/run_py.sh

BIN
src/api/hy/qr.gif


BIN
src/api/hy/qr_resized.gif


+ 60 - 0
src/api/qm_mf/qm_mf_search_book.js

@@ -59,6 +59,66 @@ CMD.search_id = async function (bookId) {
     }
 }
 
+CMD.search_name = async function (book_author,origin_book_name) {
+    const url = 'https://new-media-iaa-fx.qimao.com/api/content/book/list';
+    
+    // 请求参数
+    const params = new URLSearchParams({
+        book_author: encodeURIComponent(book_author),
+        book_name:encodeURIComponent(origin_book_name),
+        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){
+            throw -1
+        }
+        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) {
+        if(error==-1){ //这本书没有iaa对应
+            console.error("这本书没有iaa对应")
+        }
+        return null
+    }
+}
 // Node.js 18及以上版本可以直接运行
 // Node.js 18以下版本需要先安装 node-fetch:
 // npm install node-fetch@2

+ 18 - 0
task_script.json

@@ -0,0 +1,18 @@
+{
+    "apps": [
+        {
+            "name": "qm_mf_book_async",
+            "script": "./qm_mf_book_async.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/qm_mf_book_async_error.log",
+            "out_file": "./logs/task_script/qm_mf_book_async_out.log",
+            "merge_logs": true,
+            "exec_mode": "fork",
+            "autorestart": true
+        }
+    ]
+}