Curating and fetching images from imgur. Crudely saving to disk.
This commit is contained in:
parent
383a944719
commit
bdae9893c4
|
@ -1,4 +1,5 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
config/*.js
|
config/*.js
|
||||||
!config/example.js
|
!config/example.js
|
||||||
dist/*
|
/*
|
||||||
|
output/
|
||||||
|
|
30
app.js
30
app.js
|
@ -1,22 +1,42 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
|
const util = require('util');
|
||||||
|
const note = require('note-log');
|
||||||
const yargs = require('yargs').argv;
|
const yargs = require('yargs').argv;
|
||||||
const snoowrap = require('snoowrap');
|
const snoowrap = require('snoowrap');
|
||||||
|
const methods = require('./methods/methods.js');
|
||||||
console.log(yargs.user);
|
const dissectLink = require('./dissectLink.js');
|
||||||
|
const fetchContent = require('./fetchContent.js');
|
||||||
|
|
||||||
const reddit = new snoowrap(config.api);
|
const reddit = new snoowrap(config.api);
|
||||||
|
|
||||||
reddit.getUser(yargs.user).getSubmissions({
|
reddit.getUser(yargs.user).getSubmissions({
|
||||||
sort: 'top'
|
sort: 'top'
|
||||||
}).then(submissions => {
|
}).then(submissions => {
|
||||||
const details = submissions.map(submission => {
|
const curatedPosts = submissions.map(submission => {
|
||||||
return {
|
return {
|
||||||
|
id: submission.id,
|
||||||
title: submission.title,
|
title: submission.title,
|
||||||
url: submission.url
|
permalink: submission.permalink,
|
||||||
|
url: submission.url,
|
||||||
|
host: dissectLink(submission.url)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(details);
|
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;
|
||||||
|
}, []));
|
||||||
|
}).then(fetchContent).catch(error => {
|
||||||
|
note(error);
|
||||||
});
|
});
|
||||||
|
|
|
@ -556,6 +556,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
|
||||||
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw="
|
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw="
|
||||||
},
|
},
|
||||||
|
"node-fetch": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz",
|
||||||
|
"integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U="
|
||||||
|
},
|
||||||
"note-log": {
|
"note-log": {
|
||||||
"version": "2.1.11",
|
"version": "2.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/note-log/-/note-log-2.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/note-log/-/note-log-2.1.11.tgz",
|
||||||
|
@ -847,6 +852,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz",
|
||||||
"integrity": "sha1-+nG63UQ3r0wUiEHjs7Fl+enlkLc="
|
"integrity": "sha1-+nG63UQ3r0wUiEHjs7Fl+enlkLc="
|
||||||
},
|
},
|
||||||
|
"url-pattern": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/url-pattern/-/url-pattern-1.0.3.tgz",
|
||||||
|
"integrity": "sha1-BAkpJHGyTyPFDWWkeTF5PStaz8E="
|
||||||
|
},
|
||||||
"uuid": {
|
"uuid": {
|
||||||
"version": "3.2.1",
|
"version": "3.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz",
|
||||||
|
|
|
@ -24,8 +24,10 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"config": "^1.30.0",
|
"config": "^1.30.0",
|
||||||
"fs-extra": "^5.0.0",
|
"fs-extra": "^5.0.0",
|
||||||
|
"node-fetch": "^2.1.2",
|
||||||
"note-log": "^2.1.11",
|
"note-log": "^2.1.11",
|
||||||
"snoowrap": "^1.15.2",
|
"snoowrap": "^1.15.2",
|
||||||
|
"url-pattern": "^1.0.3",
|
||||||
"yargs": "^11.0.0"
|
"yargs": "^11.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue