const video_product_controllers = require('./src/data_manager/Controllers/video_product_controllers');
const config = require("./etc/config.json")
const redis_help = require('./src/use_redis');
const CMD = {}

async function processTask(){
    try{
        const result = await video_product_controllers.getDataByBookPlatform({book_platform:config.platform_yuewen})
        console.log("result:",result)
        if(result.success){
            for (let index = 0; index < result.data.length; index++) {
                const product_item =  result.data[index];
                let yw_book_data = await require('./src/api/yw/yw_search_book').search_id(product_item.product_id)
                if(yw_book_data!=null){
                    await video_product_controllers.updateData({id:product_item.id},{
                                genre:yw_book_data.genre
                    })
                }
                await new Promise(resolve => setTimeout(resolve,100));
            }
        }
    }catch(e){
        console.error("processTask error:",e)
    } finally{
        console.log("finish all!!!!!")
    }

}

CMD.init = async function(){
    redis_help.connect((results)=>{
        if(results){
            processTask();
        }
    })

}

CMD.init()