Added ignore argument.
This commit is contained in:
parent
cb1d2d6eca
commit
767ae082fa
|
@ -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
|
* `--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
|
* `--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.
|
* `--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
|
### Examples
|
||||||
* `node app.js --user=ThePendulum`
|
* `node app.js --user=ThePendulum`
|
||||||
|
|
|
@ -25,6 +25,9 @@ promiseFinally.shim();
|
||||||
|
|
||||||
const limit = yargs.limit || config.fetch.limit;
|
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') {
|
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]');
|
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
|
submissions
|
||||||
}));
|
}));
|
||||||
}).then(({user, submissions}) => {
|
}).then(({user, submissions}) => {
|
||||||
const posts = curateSubmissions(submissions).slice(0, limit);
|
const posts = curateSubmissions(submissions, ignore).slice(0, limit);
|
||||||
|
|
||||||
return fetchInfo(posts).then(info => ({
|
return fetchInfo(posts).then(info => ({
|
||||||
user,
|
user,
|
||||||
|
|
|
@ -3,11 +3,20 @@
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const dissectLink = require('../dissectLink.js');
|
const dissectLink = require('../dissectLink.js');
|
||||||
|
|
||||||
function curateSubmissions(submissions) {
|
function curateSubmissions(submissions, ignore) {
|
||||||
const processed = new Set();
|
const processed = new Set();
|
||||||
|
|
||||||
return submissions.reduce((acc, submission, index) => {
|
return submissions.reduce((acc, submission, index) => {
|
||||||
const host = dissectLink(submission.url);
|
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(host) {
|
||||||
if(config.fetch.avoidDuplicates && processed.has(host.id)) {
|
if(config.fetch.avoidDuplicates && processed.has(host.id)) {
|
||||||
|
|
Loading…
Reference in New Issue