ripunzel/app.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-09-11 03:16:53 +00:00
'use strict';
const config = require('config');
const util = require('util');
const fs = require('fs-extra');
2024-09-11 03:16:53 +00:00
const yargs = require('yargs').argv;
const snoowrap = require('snoowrap');
const reddit = new snoowrap(config.reddit.api);
const curateSubmissions = require('./curate/submissions.js');
const curateUser = require('./curate/user.js');
const methods = require('./methods/methods.js');
const interpolate = require('./interpolate.js');
const fetchInfo = require('./fetch/info.js');
const fetchContent = require('./fetch/content.js');
const save = require('./save/save.js');
const saveProfileDetails = require('./save/profileDetails.js');
const limit = yargs.limit || config.fetch.limit;
2024-09-11 03:16:53 +00:00
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]');
}
const users = yargs.users ? yargs.users.split(',') : [].concat(yargs.user);
users.forEach(username => {
return Promise.resolve().then(() => {
return reddit.getUser(username).fetch().then(curateUser);
}).then(user => {
return saveProfileDetails(user);
}).then(user => {
return reddit.getUser(username).getSubmissions({
sort: yargs.sort || config.fetch.sort
}).then(submissions => ({
user,
submissions
}));
}).then(({user, submissions}) => {
const posts = curateSubmissions(submissions).slice(0, limit);
return fetchInfo(posts).then(info => ({
user,
posts
}));
}).then(({user, posts}) => {
return fetchContent(posts, user);
}).catch(error => {
return console.log(error);
});
});