Replaced Snoowrap with public API calls in response to Reddit revoking API keys. This was largely done using Claude Code, extensive manual review and major version bump needed if merged into main.
This commit is contained in:
@@ -6,11 +6,10 @@ const getIndex = require('./getIndex');
|
||||
const curateUser = require('../curate/user');
|
||||
|
||||
const logger = require('../logger')(__filename);
|
||||
const limiter = require('../limiter').reddit;
|
||||
|
||||
async function getUser(username, reddit) {
|
||||
try {
|
||||
const user = await limiter.schedule(async () => reddit.getUser(username).fetch());
|
||||
const user = await reddit.getUser(username);
|
||||
|
||||
return curateUser(user);
|
||||
} catch (error) {
|
||||
@@ -25,22 +24,22 @@ async function getUser(username, reddit) {
|
||||
|
||||
const getPostsWrap = (reddit) => function getPosts(postIds, userPosts = {}) {
|
||||
return Promise.reduce(postIds, (accUserPosts, postId) => Promise.resolve().then(async () => {
|
||||
const post = await limiter.schedule(async () => reddit.getSubmission(postId).fetch());
|
||||
const post = await reddit.getSubmission(postId);
|
||||
|
||||
post.direct = true;
|
||||
|
||||
if (accUserPosts[post.author.name]) {
|
||||
if (accUserPosts[post.author]) {
|
||||
return {
|
||||
...accUserPosts,
|
||||
[post.author.name]: {
|
||||
...accUserPosts[post.author.name],
|
||||
posts: [...accUserPosts[post.author.name].posts, post],
|
||||
[post.author]: {
|
||||
...accUserPosts[post.author],
|
||||
posts: [...accUserPosts[post.author].posts, post],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// don't attempt to fetch deleted user
|
||||
if (post.author.name === '[deleted]') {
|
||||
if (post.author === '[deleted]') {
|
||||
return {
|
||||
...accUserPosts,
|
||||
'[deleted]': {
|
||||
@@ -56,12 +55,12 @@ const getPostsWrap = (reddit) => function getPosts(postIds, userPosts = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
const user = await getUser(post.author.name, reddit);
|
||||
const user = await getUser(post.author, reddit);
|
||||
const { profile, posts: indexed } = await getIndex(user);
|
||||
|
||||
return {
|
||||
...accUserPosts,
|
||||
[post.author.name]: {
|
||||
[post.author]: {
|
||||
...user,
|
||||
posts: [post],
|
||||
indexed: {
|
||||
|
||||
@@ -7,11 +7,10 @@ const getArchivePostIds = require('../archives/getArchivePostIds');
|
||||
const curateUser = require('../curate/user');
|
||||
|
||||
const logger = require('../logger')(__filename);
|
||||
const limiter = require('../limiter').reddit;
|
||||
|
||||
async function getUser(username, reddit) {
|
||||
try {
|
||||
const user = await limiter.schedule(async () => reddit.getUser(username).fetch());
|
||||
const user = await reddit.getUser(username);
|
||||
|
||||
logger.info(`Fetched user profile for '${username}' (https://reddit.com/user/${username})`);
|
||||
|
||||
@@ -28,12 +27,10 @@ async function getUser(username, reddit) {
|
||||
|
||||
async function getPosts(username, reddit, args) {
|
||||
try {
|
||||
const submissions = await limiter.schedule(async () => reddit
|
||||
.getUser(username)
|
||||
.getSubmissions({
|
||||
sort: args.sort,
|
||||
limit: Infinity,
|
||||
}));
|
||||
const submissions = await reddit.getSubmissions(username, {
|
||||
sort: args.sort,
|
||||
limit: Infinity,
|
||||
});
|
||||
|
||||
logger.info(`Fetched ${submissions.length} submissions for '${username}' (https://reddit.com/user/${username})`);
|
||||
|
||||
@@ -48,7 +45,7 @@ async function getPosts(username, reddit, args) {
|
||||
async function getArchivedPosts(username, posts, reddit) {
|
||||
const postIds = await getArchivePostIds(username, posts.map((post) => post.id));
|
||||
|
||||
return Promise.all(postIds.map((postId) => limiter.schedule(async () => reddit.getSubmission(postId).fetch())));
|
||||
return Promise.all(postIds.map((postId) => reddit.getSubmission(postId)));
|
||||
}
|
||||
|
||||
function getUserPostsWrap(reddit, args) {
|
||||
|
||||
Reference in New Issue
Block a user