snoowrap
snoowrap copied to clipboard
Fetch multireddit submissions
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)?
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).
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.
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.
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.
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
.
It makes sense. I agree.
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?
You could use oauthRequest
and set the URL manually.
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;