Fetching and storing comments for self posts.

This commit is contained in:
2024-09-11 05:16:58 +02:00
parent 926ab1d25c
commit 7de0c51c16
11 changed files with 272 additions and 149 deletions

View File

@@ -5,7 +5,7 @@ const Promise = require('bluebird');
const getIndex = require('./getIndex.js');
const curateUser = require('../curate/user.js');
const getUser = async (username, reddit) => {
async function getUser(username, reddit) {
try {
const user = await reddit.getUser(username).fetch();
@@ -22,7 +22,9 @@ const getUser = async (username, reddit) => {
const getPostsWrap = reddit => function getPosts(postIds, userPosts = {}) {
return Promise.reduce(postIds, (accUserPosts, postId) => Promise.resolve().then(async () => {
const post = await reddit.getSubmission(postId).fetch();
const post = await reddit
.getSubmission(postId)
.fetch();
post.direct = true;
@@ -34,13 +36,31 @@ const getPostsWrap = reddit => function getPosts(postIds, userPosts = {}) {
// don't attempt to fetch deleted user
if (post.author.name === '[deleted]') {
return { ...accUserPosts, '[deleted]': { name: '[deleted]', deleted: true, posts: [post] } };
return {
...accUserPosts,
'[deleted]': {
name: '[deleted]',
deleted: true,
posts: [post],
},
};
}
const user = await getUser(post.author.name, reddit);
const { profile, posts: indexed } = await getIndex(user);
return { ...accUserPosts, [post.author.name]: { ...user, posts: [post], indexed: { profile, original: indexed, updated: [] } } };
return {
...accUserPosts,
[post.author.name]: {
...user,
posts: [post],
indexed: {
profile,
original: indexed,
updated: [],
},
},
};
}), userPosts);
};

View File

@@ -25,10 +25,12 @@ async function getUser(username, reddit) {
async function getPosts(username, reddit, args) {
try {
const submissions = await reddit.getUser(username).getSubmissions({
sort: args.sort,
limit: Infinity,
});
const submissions = await reddit
.getUser(username)
.getSubmissions({
sort: args.sort,
limit: Infinity,
});
console.log(`Fetched ${submissions.length} submissions for '${username}' (https://reddit.com/user/${username})`);