48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const config = require('config');
|
|
const util = require('util');
|
|
const yargs = require('yargs').argv;
|
|
const snoowrap = require('snoowrap');
|
|
const methods = require('./methods/methods.js');
|
|
const dissectLink = require('./dissectLink.js');
|
|
const fetchContent = require('./fetchContent.js');
|
|
|
|
const reddit = new snoowrap(config.reddit.api);
|
|
|
|
reddit.getUser(yargs.user).getSubmissions({
|
|
sort: yargs.sort || config.reddit.sort,
|
|
limit: yargs.limit || config.reddit.limit
|
|
}).then(submissions => {
|
|
const curatedPosts = submissions.map((submission, index) => {
|
|
return {
|
|
id: submission.id,
|
|
index: index,
|
|
title: submission.title,
|
|
text: submission.selftext,
|
|
user: submission.author.name,
|
|
permalink: submission.permalink,
|
|
url: submission.url,
|
|
datetime: submission.created_utc * 1000,
|
|
subreddit: submission.subreddit.display_name,
|
|
host: dissectLink(submission.url)
|
|
};
|
|
});
|
|
|
|
return Promise.all(curatedPosts.reduce((acc, post) => {
|
|
if(post.host && methods[post.host.method]) {
|
|
acc = acc.concat(methods[post.host.method](post).then(content => {
|
|
post.content = content;
|
|
|
|
return post;
|
|
}));
|
|
} else {
|
|
console.log('\x1b[33m%s\x1b[0m', `"${post.title}": '${post.url}' not supported :(`);
|
|
}
|
|
|
|
return acc;
|
|
}, []));
|
|
}).then(posts => fetchContent(posts)).catch(error => {
|
|
console.error(error);
|
|
});
|