添加hifini_music爬虫代码
This commit is contained in:
		
							
								
								
									
										43
									
								
								hifini_music/src/dataManager.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								hifini_music/src/dataManager.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
const dbUtils = global.dbUtils;
 | 
			
		||||
 | 
			
		||||
let insertCollectionTemplate = async (tableName, dataList) => {
 | 
			
		||||
    if (dataList.length == 0) return;
 | 
			
		||||
    return await dbUtils.query(`
 | 
			
		||||
        INSERT INTO ${tableName} ( ${Object.keys(dataList[0]).map(field => `\`${field}\``).join(",")} ) VALUES ?
 | 
			
		||||
        ON DUPLICATE KEY UPDATE ${Object.keys(dataList[0]).map(field => `${field}=VALUES(${field})`).join(", ")}
 | 
			
		||||
    `, [dataList.map(item => Object.values(item))]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
 | 
			
		||||
    thread: {
 | 
			
		||||
        insertCollection: async (threadList) => {
 | 
			
		||||
            return await insertCollectionTemplate("hifini_thread", threadList);
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        update: async (threadId, threadInfo) => {
 | 
			
		||||
            return await dbUtils.query(`UPDATE hifini_thread SET ? WHERE thread_id = ${threadId}`, threadInfo);
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        getIdsToFetch: async () => {
 | 
			
		||||
            return await dbUtils.query(`SELECT thread_id FROM hifini_thread where music_title='' and music_pic='' and music_url=''`);
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        getIdsToFetchRealUrl: async () => {
 | 
			
		||||
            return await dbUtils.query(`SELECT thread_id,music_url FROM hifini_thread where music_url like 'get_music.php?key=%' and music_real_url=''`);
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    tag: {
 | 
			
		||||
        insertCollection: async (tagList) => {
 | 
			
		||||
            return await insertCollectionTemplate("hifini_tag", tagList);
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    thread_tag: {
 | 
			
		||||
        insertCollection: async (tagList) => {
 | 
			
		||||
            return await insertCollectionTemplate("hifini_thread_tag_relation", tagList);
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user