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