fetchAll从index.js提到各个utils中
This commit is contained in:
@@ -2,6 +2,7 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const requestUtils = require('../../../utils/requestUtils');
|
||||
const sleepUtils = require('../../../utils/sleepUtils');
|
||||
|
||||
const dbUtils = global.dbUtils;
|
||||
|
||||
@@ -20,6 +21,26 @@ async function getFromDatabase({ artistId }) {
|
||||
return artistInfo;
|
||||
}
|
||||
|
||||
// 从数据库中查出还缺少的歌手,并进行爬取
|
||||
async function fetchAll() {
|
||||
console.log("start fetching artists ...")
|
||||
var artistIds = await dbUtils.query(`
|
||||
SELECT DISTINCT artist_id FROM song_artist_relation WHERE artist_id NOT IN ( SELECT DISTINCT artist_id FROM artist )
|
||||
`, []);
|
||||
artistIds = artistIds.map(item => item.artist_id);
|
||||
for (let i = 0; i < artistIds.length; i++) {
|
||||
await global.checkIsExit();
|
||||
const artistId = artistIds[i];
|
||||
console.log(`${i}/${artistIds.length} | artist: ${artistId} | ${await global.statistics()}`);
|
||||
try {
|
||||
await fetch({ artistId: artistId });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
await sleepUtils.sleep(global.sleepTime);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取音乐人详情
|
||||
async function fetch({ artistId, debug = false }) {
|
||||
let result = await dbUtils.query('SELECT count(*) as count FROM artist WHERE artist_id = ?', [artistId]);
|
||||
@@ -85,4 +106,5 @@ async function fetch({ artistId, debug = false }) {
|
||||
module.exports = {
|
||||
getFromDatabase: getFromDatabase,
|
||||
fetch: fetch,
|
||||
fetchAll: fetchAll,
|
||||
}
|
Reference in New Issue
Block a user