2018-04-09 22:26:30 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require('config');
|
2018-04-15 01:55:10 +00:00
|
|
|
const util = require('util');
|
|
|
|
const note = require('note-log');
|
2018-04-09 22:26:30 +00:00
|
|
|
const yargs = require('yargs').argv;
|
|
|
|
const snoowrap = require('snoowrap');
|
2018-04-15 01:55:10 +00:00
|
|
|
const methods = require('./methods/methods.js');
|
|
|
|
const dissectLink = require('./dissectLink.js');
|
|
|
|
const fetchContent = require('./fetchContent.js');
|
2018-04-09 22:26:30 +00:00
|
|
|
|
2018-04-16 21:46:39 +00:00
|
|
|
const reddit = new snoowrap(config.reddit);
|
2018-04-09 22:26:30 +00:00
|
|
|
|
2018-04-16 21:46:39 +00:00
|
|
|
reddit.getUser(yargs.user).getSubmissions({
|
|
|
|
sort: 'top',
|
|
|
|
limit: Infinity
|
2018-04-09 22:26:30 +00:00
|
|
|
}).then(submissions => {
|
2018-04-15 01:55:10 +00:00
|
|
|
const curatedPosts = submissions.map(submission => {
|
2018-04-09 22:26:30 +00:00
|
|
|
return {
|
2018-04-15 01:55:10 +00:00
|
|
|
id: submission.id,
|
2018-04-09 22:26:30 +00:00
|
|
|
title: submission.title,
|
2018-04-16 21:46:39 +00:00
|
|
|
user: submission.author.name,
|
2018-04-15 01:55:10 +00:00
|
|
|
permalink: submission.permalink,
|
|
|
|
url: submission.url,
|
2018-04-16 21:46:39 +00:00
|
|
|
datetime: submission.created_utc * 1000,
|
2018-04-15 02:51:02 +00:00
|
|
|
subreddit: submission.subreddit.display_name,
|
2018-04-15 01:55:10 +00:00
|
|
|
host: dissectLink(submission.url)
|
2018-04-09 22:26:30 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2018-04-15 01:55:10 +00:00
|
|
|
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 {
|
|
|
|
note('fetch', 1, `"${post.title}": '${post.url}' not supported :(`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, []));
|
2018-04-16 21:46:39 +00:00
|
|
|
}).then(posts => fetchContent(posts)).catch(error => {
|
2018-04-15 01:55:10 +00:00
|
|
|
note(error);
|
2018-04-09 22:26:30 +00:00
|
|
|
});
|