From 767ae082facdfda23c20eaa6538ecedf36af4bde Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 11 Sep 2024 05:16:54 +0200 Subject: [PATCH] Added ignore argument. --- README.md | 1 + src/app.js | 5 ++++- src/curate/submissions.js | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e54eea0..6c907fb 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/app.js b/src/app.js index ab2a52a..a200d80 100644 --- a/src/app.js +++ b/src/app.js @@ -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, diff --git a/src/curate/submissions.js b/src/curate/submissions.js index 7eea792..2a23146 100644 --- a/src/curate/submissions.js +++ b/src/curate/submissions.js @@ -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)) {