snoowrap icon indicating copy to clipboard operation
snoowrap copied to clipboard

Fetch multireddit submissions

Open papagno opened this issue 7 years ago • 9 comments

By reading the documentation I couldn't find a way to fetch submissions for a multireddit. Is it possible with snoowrap (or the reddit APIs)?

papagno avatar Mar 27 '17 20:03 papagno

No, it's not possible at the moment. This seems like something that should be added.

As a workaround, you can fetch posts from multiple subreddits at a time using r.getSubreddit('foo+bar') (which gets all posts from /r/foo+bar).

not-an-aardvark avatar Mar 30 '17 01:03 not-an-aardvark

Ok, thanks. Maybe we could add an alias for that request to MultiReddit. Unless you want the library to match exactly the official reddit API.

papagno avatar Mar 30 '17 06:03 papagno

The /r/foo+bar thing just gets posts from two subreddits at the same time, but I think multireddits are actually a separate type of thing. It seems like there's an (undocumented) way to get a list of posts in a multireddit here, so snoowrap could probably use that.

not-an-aardvark avatar Mar 30 '17 06:03 not-an-aardvark

The data structure seems to be the same. Is the data set different? I would go with /r/foo+bar because the multireddit API is undocumented.

papagno avatar Mar 30 '17 06:03 papagno

I don't think /r/foo+bar is documented either. I suspect the multireddit API is roughly the same, but it's possible there are subtle differences. It seems like it would be more intuitive for snoowrap to display what would actually appear on a multireddit rather than a hack like /r/foo+bar.

not-an-aardvark avatar Mar 30 '17 07:03 not-an-aardvark

It makes sense. I agree.

papagno avatar Mar 30 '17 07:03 papagno

In the meantime, I've been trying to figure out how to go about this best I can utilizing your wrapper. I think it's a bit cleaner to do the get on "https://www.reddit.com/user/Lapper/m/depthhub/.json" route versus the (foo+bar) route but I can only think of how to do the latter way via your api. How would you do it the former way?

lumberbeard avatar Oct 31 '17 23:10 lumberbeard

You could use oauthRequest and set the URL manually.

not-an-aardvark avatar Nov 01 '17 05:11 not-an-aardvark

The below code is what I'm using to get multireddit submissions. Beware that this function makes a request per 100 submissions. Use at your own risk:

async function GetMultireddit(user, multireddit, count, options) {
    let posts = []
    let previousAfter = null;
    try {
        for (let i = 0; i < count; i += 100) {
            let amount = (i + 100 > count) ? (count - i) : (100) // query 100 or remainder
            let chunk = await Reddit.oauthRequest({uri: `/user/${user}/m/${multireddit}/.json`,
                                                   method: 'get',
                                                   qs:{limit: amount, after: previousAfter}})
            chunk.forEach((submission, index) => posts.push(submission)) // for each submission, push to posts
            previousAfter = chunk._query.after;
        }
    } catch (err) {
        console.log(err);
    }

    return posts;
}
module.exports.GetMultireddit = GetMultireddit;

BinarySpike avatar Dec 08 '18 10:12 BinarySpike