Curating and fetching images from imgur. Crudely saving to disk.

This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:53 +02:00
parent 383a944719
commit bdae9893c4
4 changed files with 39 additions and 6 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
node_modules/
config/*.js
!config/example.js
dist/*
/*
output/

30
app.js
View File

@ -1,22 +1,42 @@
'use strict';
const config = require('config');
const util = require('util');
const note = require('note-log');
const yargs = require('yargs').argv;
const snoowrap = require('snoowrap');
console.log(yargs.user);
const methods = require('./methods/methods.js');
const dissectLink = require('./dissectLink.js');
const fetchContent = require('./fetchContent.js');
const reddit = new snoowrap(config.api);
reddit.getUser(yargs.user).getSubmissions({
sort: 'top'
}).then(submissions => {
const details = submissions.map(submission => {
const curatedPosts = submissions.map(submission => {
return {
id: submission.id,
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);
});

10
package-lock.json generated
View File

@ -556,6 +556,11 @@
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
"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": {
"version": "2.1.11",
"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",
"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": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz",

View File

@ -24,8 +24,10 @@
"dependencies": {
"config": "^1.30.0",
"fs-extra": "^5.0.0",
"node-fetch": "^2.1.2",
"note-log": "^2.1.11",
"snoowrap": "^1.15.2",
"url-pattern": "^1.0.3",
"yargs": "^11.0.0"
}
}