forked from appetizermonster/steempages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetcher.js
44 lines (38 loc) · 1.04 KB
/
fetcher.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
'use strict';
const steem = require('steem');
function getDateForSteem() {
return new Date().toISOString().replace('Z', '');
}
async function fetchAllPosts(author) {
const limit = 10;
const date = getDateForSteem();
const permlinks = {};
const results = [];
let nextPermlink = null;
while (true) {
const posts = await steem.api.getDiscussionsByAuthorBeforeDate(author, nextPermlink, date, limit);
const noMorePosts = (nextPermlink !== null && posts.length <= 1);
if (noMorePosts)
break;
for (const post of posts) {
const permlink = post.permlink;
if (permlink in permlinks)
continue;
permlinks[permlink] = true;
const metadata = JSON.parse(post.json_metadata);
const result = {
created: post.created,
permlink: post.permlink,
title: post.title,
body: post.body,
tags: metadata.tags
};
results.push(result);
}
nextPermlink = posts[posts.length - 1].permlink;
}
return results;
}
module.exports = {
fetchAllPosts
};