This repository has been archived by the owner on Apr 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
00-get-posts.js
111 lines (94 loc) · 2.89 KB
/
00-get-posts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require('dotenv-safe').config();
const easyvk = require('easyvk');
const { writeJson } = require('./__common');
const {
LOGIN,
PASSWORD,
} = process.env;
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
async function get_posts(vk, n, owner_id) {
const promises = [];
let total_count, left, offset = 0, max_count = 100;
const { vkr: sub_wall } = await vk.call('wall.get', {
count: 1,
owner_id
});
total_count = sub_wall.count;
left = Math.min(total_count, n);
console.log(`Loading ${n}. Total ${total_count}`);
while (offset < left) {
promises.push(vk.call('wall.get', {
offset,
count: max_count,
owner_id,
}).then(({ vkr }) => {
console.log(`[${vkr.queryData.offset}/${left}]`)
// console.log(vkr);
// console.log(`+=${vkr.items.length}`);
return vkr;
}));
offset += max_count;
await sleep(1);
}
let wall = await Promise.all(promises);
return {
count: total_count,
items: wall.flatMap(w => w.items)
};
}
async function get_posts_seq(vk, n, owner_id) {
let total_count, left, offset = 0, max_count = 100;
const { vkr: sub_wall } = await vk.call('wall.get', {
count: 1,
owner_id
});
total_count = sub_wall.count;
left = Math.min(total_count, n);
console.log(`Loading ${n}. Total ${total_count}`);
const wall = [];
while (offset < left) {
const sub_wall = await vk.call('wall.get', {
offset,
count: max_count,
owner_id,
}).then(({ vkr }) => {
console.log(`[${vkr.queryData.offset}/${left}]`)
// console.log(vkr);
// console.log(`+=${vkr.items.length}`);
return vkr;
});
wall.push(sub_wall);
offset += max_count;
}
return {
count: total_count,
items: wall.flatMap(w => w.items)
};
}
easyvk({
username: LOGIN,
password: PASSWORD,
session_file: __dirname + '/.my-session'
}).then(async vk => {
let { vkr: groups } = await vk.call('groups.get', {
extended: true
});
// console.log(groups);
groups = groups.items.filter(g =>
g.name.includes('VΛ') || g.screen_name.includes('vatriume')
);
if (groups.length == 0) {
console.log('Cannot find VA');
process.exit(1);
}
const atrium_id = groups[0].id;
console.log(`Identified target as [${groups[0].id}]${groups[0].screen_name}`);
const first_n = 100 * 1000;
const wall = await get_posts_seq(vk, first_n, -atrium_id);
// const with_photos = wall.items.filter(hasPhotoAttachment);
// console.log(with_photos);
// console.log(`[${with_photos.length}/${wall.items.length}/${wall.count}]`);
writeJson(`./data/all_posts.${first_n}.min.json`, wall);
});