Fetching and storing comments for self posts.
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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})`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user