Added ignore argument.

This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:54 +02:00
parent cb1d2d6eca
commit 767ae082fa
3 changed files with 15 additions and 2 deletions

View File

@ -39,6 +39,7 @@ reddit-post-dump requires a arbitrarily recent version of Node.js. Before use, d
* `--users={user1,user2}`: You may fetch posts from multiple users by either supplying a comma-separated list of usernames (no spaces) with `--users`, or by using multiple individual `--user` arguments
* `--limit={number}`: Maximum amount posts per user to fetch content from
* `--sort={method}`: How posts should be sorted while fetched. This affects the `$postIndex` variable, and in combination with a `--limit` decides what posts will be included.
* `--ignore={prop1,prop2}`: Ignore submissions that have any of these properties. Supported properties include `pinned`, `stickied`, `hidden`, `over_18`, `spoiler` (protip: any property in the API response can be ignored, if desired).
### Examples
* `node app.js --user=ThePendulum`

View File

@ -25,6 +25,9 @@ promiseFinally.shim();
const limit = yargs.limit || config.fetch.limit;
// allow for any combination of --ignore val1 --ignore val2, --ignore=val1,val2
const ignore = yargs.ignore ? [].concat(yargs.ignore).reduce((acc, prop) => acc.concat(prop.split(',')), []) : [];
if(!yargs.user && typeof yargs.users !== 'string') {
return console.log('\x1b[31m%s\x1b[0m', 'Please supply at least one user with --user=[user], or multiple users with --users=[user1,user2] or --user=[user1] --user=[user2]');
}
@ -45,7 +48,7 @@ users.forEach(username => {
submissions
}));
}).then(({user, submissions}) => {
const posts = curateSubmissions(submissions).slice(0, limit);
const posts = curateSubmissions(submissions, ignore).slice(0, limit);
return fetchInfo(posts).then(info => ({
user,

View File

@ -3,11 +3,20 @@
const config = require('config');
const dissectLink = require('../dissectLink.js');
function curateSubmissions(submissions) {
function curateSubmissions(submissions, ignore) {
const processed = new Set();
return submissions.reduce((acc, submission, index) => {
const host = dissectLink(submission.url);
const ignoring = ignore.find(prop => {
return submission[prop];
});
if(ignoring) {
console.log('\x1b[33m%s\x1b[0m', `Ignoring ${ignoring} post '${submission.title}' - ${submission.url}`);
return acc;
}
if(host) {
if(config.fetch.avoidDuplicates && processed.has(host.id)) {