输出对齐(填充空格)
This commit is contained in:
parent
c02dcdf814
commit
d332563905
@ -1,6 +1,7 @@
|
||||
// 定时更新 wait 表
|
||||
|
||||
const sleepUtils = require("../../utils/sleepUtils");
|
||||
const { fill } = require("../../utils/stringUtils");
|
||||
|
||||
// 计算数组差集 (a - b)
|
||||
function getDiffSet(a, b) {
|
||||
@ -12,7 +13,7 @@ function getDiffSet(a, b) {
|
||||
}
|
||||
|
||||
async function migrateIdsFromCheckToFetch(tableName, fieldName, insertSql = null) {
|
||||
console.log(`更新待爬取列表: ${tableName}`);
|
||||
// console.log(`更新待爬取列表: ${tableName}`);
|
||||
|
||||
let stepLength = 5000;
|
||||
while (true) {
|
||||
@ -40,10 +41,11 @@ async function migrateIdsFromCheckToFetch(tableName, fieldName, insertSql = null
|
||||
// console.log(result);
|
||||
}
|
||||
|
||||
|
||||
// 从待检查表中删除
|
||||
if (ids.length > 0)
|
||||
await dbUtils.query(`DELETE FROM wait_check_${tableName} WHERE id IN ?`, [[ids]]);
|
||||
console.log(`table: ${tableName} | ${ids[0]} - ${ids.slice(-1)[0]} (${result?.affectedRows}/${finalIds.length}/${ids.length})`);
|
||||
console.log(`table: ${tableName}\t| ${fill(ids[0], 10)} - ${fill(ids.slice(-1)[0], 10)} ${fill(`(${finalIds.length}/${ids.length})`, 10, ' ', true)}\t| affected: ${result?.affectedRows}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,6 +61,7 @@ async function getPromise(tableName, fieldName, insertSql) {
|
||||
}
|
||||
}
|
||||
async function updateWaitTable() {
|
||||
console.log(`更新待爬取列表`);
|
||||
await Promise.all([
|
||||
getPromise("song", "song_id"),
|
||||
getPromise("lyric", "song_id"),
|
||||
|
@ -3,6 +3,7 @@ const path = require('path');
|
||||
|
||||
const requestUtils = require('../../../utils/requestUtils');
|
||||
const sleepUtils = require('../../../utils/sleepUtils');
|
||||
const { fill } = require('../../../utils/stringUtils');
|
||||
const dataManager = require('../dataManager');
|
||||
|
||||
const dbUtils = global.dbUtils;
|
||||
@ -21,7 +22,7 @@ async function fetchAll({ args = {} }) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
await global.checkIsExit();
|
||||
var subArray = songIds.slice(i * step, (i + 1) * step);
|
||||
console.log(`${i + 1}/${count} | song: ${subArray[0]}-${subArray.slice(-1)[0]} (${subArray.length}) | ${args.min || "?"}-${args.max || "?"}`);
|
||||
console.log(`${i + 1}/${count} | song: ${fill(subArray[0], 10)}-${fill(subArray.slice(-1)[0], 10)} ${fill(`(${subArray.length})`, 6, ' ', true)} | ${args.min || "?"}-${args.max || "?"}`);
|
||||
try {
|
||||
await fetch({ songIdArray: subArray });
|
||||
} catch (err) {
|
||||
|
13
utils/stringUtils.js
Normal file
13
utils/stringUtils.js
Normal file
@ -0,0 +1,13 @@
|
||||
// 数字转成字符串,同时在前面填充
|
||||
function fill(num, length, fillers = " ", atLast = false) {
|
||||
var result = `${num}`;
|
||||
if (result.length < length) {
|
||||
let fillString = new Array(length - result.length + 1).join(fillers)
|
||||
result = atLast ? `${result}${fillString}` : `${fillString}${result}`;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fill,
|
||||
}
|
Loading…
Reference in New Issue
Block a user