mirror of
https://github.com/anatolykopyl/vk-nft-feed.git
synced 2026-03-26 12:54:33 +00:00
Добавил прогресс бар и вывел id в cli args
This commit is contained in:
17
getImages.js
17
getImages.js
@@ -1,3 +1,4 @@
|
||||
import ProgressBar from 'progress';
|
||||
import getPosts from './getPosts.js';
|
||||
import post2Svg from './post2Svg.js';
|
||||
|
||||
@@ -19,11 +20,25 @@ async function getAllPosts(owner_id) {
|
||||
let finished = false;
|
||||
let offset = 0;
|
||||
let posts = [];
|
||||
let bar;
|
||||
|
||||
while (!finished) {
|
||||
const response = await getPosts(owner_id, offset);
|
||||
const total = response.count;
|
||||
|
||||
if (!bar) {
|
||||
bar = new ProgressBar(
|
||||
'Getting posts [:bar] :current/:total :percent',
|
||||
{
|
||||
total,
|
||||
width: 30,
|
||||
}
|
||||
);
|
||||
}
|
||||
bar.tick(response.items.length);
|
||||
|
||||
posts = posts.concat(response.items);
|
||||
if (posts.length === response.count) {
|
||||
if (posts.length === total) {
|
||||
finished = true;
|
||||
} else {
|
||||
offset += response.items.length;
|
||||
|
||||
Reference in New Issue
Block a user