fix some stuff

This commit is contained in:
Tykayn 2021-10-22 14:17:19 +02:00 committed by tykayn
parent debae70091
commit afef2388dc
4 changed files with 243 additions and 240 deletions

View File

@ -26,6 +26,7 @@ class Conversion {
console.log('likes length', lengthOfLikes); console.log('likes length', lengthOfLikes);
return jsonParsedLikes; return jsonParsedLikes;
}); });
return {}
} }
filterToots(toots, options) { filterToots(toots, options) {
@ -36,19 +37,24 @@ class Conversion {
if (filter) { if (filter) {
if (options.filterOnlyHavingMedias) {
toots = masto_converter.conversion.filterOnlyTootsWithMedias(toots);
console.log('toots.length only attachements', toots.length);
}
if (options.showMostRecentTootsOnTop) { if (options.showMostRecentTootsOnTop) {
filteredToots = filteredToots.reverse(); filteredToots = filteredToots.reverse();
} }
if (options.filterBiggerTootsBeforeSlicing) { if (options.filterBiggerTootsBeforeSlicing) {
console.log('min length of content of toots ', options.min_length );
filteredToots = filteredToots.filter(item => { filteredToots = filteredToots.filter(item => {
return (item['object'].content && item['object'].content.length > options.min_length && item['object'].content.length < options.max_length); return (item['object'].content && item['object'].content.length >= options.min_length && item['object'].content.length <= options.max_length);
}); });
filteredToots = filteredToots.slice(0, options.max_toots); filteredToots = filteredToots.slice(0, options.max_toots);
} else { } else {
const slice = toots.slice(0, options.max_toots); const slice = toots.slice(0, options.max_toots);
filteredToots = slice.filter(item => { filteredToots = slice.filter(item => {
return (item['object'].content && item['object'].content.length > options.min_length && item['object'].content.length < options.max_length); return (item['object'].content && item['object'].content.length >= options.min_length && item['object'].content.length <= options.max_length);
}); });
} }
// filteredToots.forEach(toot => { // filteredToots.forEach(toot => {
@ -181,10 +187,12 @@ class Conversion {
} }
filterOnlyTootsWithMedias(tootList) { filterOnlyTootsWithMedias(tootList) {
console.log('filterOnlyTootsWithMedias'); console.log('filterOnlyTootsWithMedias from', tootList.length);
return tootList.filter(toot => { let filtered = tootList.filter(toot => {
return toot['object'].attachment && toot['object'].attachment.length; return toot['object'].attachment && toot['object'].attachment.length;
}); });
console.log('to ', filtered.length);
return filtered
} }
@ -231,19 +239,19 @@ class Conversion {
const self = this; const self = this;
const ax = axios.create(headers); const ax = axios.create(headers);
ax.get().then(function (response) { // ax.get().then(function (response) {
// handle success // // handle success
// avatar is response.data.icon.url // // avatar is response.data.icon.url
// cover is response.data.image.url // // cover is response.data.image.url
// console.log(response.data.icon); // // console.log(response.data.icon);
// console.log(response.data.image); // // console.log(response.data.image);
//
if (!self.usersMemo[accountHandle + '@' + instanceHandle]) { // if (!self.usersMemo[accountHandle + '@' + instanceHandle]) {
self.usersMemo[accountHandle + '@' + instanceHandle] = {}; // self.usersMemo[accountHandle + '@' + instanceHandle] = {};
} // }
self.usersMemo[accountHandle + '@' + instanceHandle] = response.data; // self.usersMemo[accountHandle + '@' + instanceHandle] = response.data;
return response.data; // return response.data;
}); // });
} }

22
main.js
View File

@ -13,16 +13,16 @@ var jsonParsedLikes, jsonParsedOutbox;
* export configuration. * export configuration.
* You can filter the export in the following vars * You can filter the export in the following vars
*/ */
const min_length = 500; // minmum character length of toots to display const min_length = 300; // minmum character length of toots to display
const max_length = 100000; // minmum character length of toots to display const max_length = 100000; // max character length of toots to display
const max_toots = 20// maximum length const max_toots = 200// maximum count of output
const filterBiggerTootsBeforeSlicing = false; // filter only long toots const filterBiggerTootsBeforeSlicing = false; // filter only long toots
const filterOnlyHavingMedias = true; // filter only toots having medias const filterOnlyHavingMedias = false; // filter only toots having medias
const displayMedias = false; // display medias in toots const displayMedias = false; // display medias in toots
const showMostRecentTootsOnTop = true; // sorting order const showMostRecentTootsOnTop = true; // sorting order
// output write // output write
const writeStatsJson = false; // write json export file about statistics const writeStatsJson = false; // write json export file about statistics
const writeHtml = true; // write json export file about statistics const writeHtml = false; // write json export file about statistics
const TemplateVars = { const TemplateVars = {
pageTitle : 'Mastodon export converter to HTML', pageTitle : 'Mastodon export converter to HTML',
@ -57,14 +57,10 @@ fs.readFile('source_data/outbox.json',
jsonParsedOutbox = JSON.parse(data); jsonParsedOutbox = JSON.parse(data);
toots = jsonParsedOutbox.orderedItems; toots = jsonParsedOutbox.orderedItems;
// access elements // access elements
console.log('outbox toots length', toots.length); console.log('-------- outbox toots length', toots.length);
TemplateVars.outboxTotalLength = toots.length; TemplateVars.outboxTotalLength = toots.length;
toots = jsonParsedOutbox.orderedItems;
if (filterOnlyHavingMedias) {
toots = masto_converter.conversion.filterOnlyTootsWithMedias(toots);
console.log('toots.length only attachements', toots.length);
}
toots = masto_converter.conversion.filterToots(toots, TemplateVars); toots = masto_converter.conversion.filterToots(toots, TemplateVars);
console.log('min_chars', min_length); console.log('min_chars', min_length);
@ -81,7 +77,7 @@ fs.readFile('source_data/outbox.json',
}); });
const errfileHandler = (err) => { const errfileHandler = (err) => {
if (err) if (err)
console.log(err); console.log('ERROR =======================' ,err);
else { else {
console.log('File statistics written successfully\n'); console.log('File statistics written successfully\n');
} }
@ -96,12 +92,10 @@ app.get('/', (req, res) => {
if(writeHtml){ if(writeHtml){
fs.writeFile('output/my_toots.html', html, errfileHandler); fs.writeFile('output/my_toots.html', html, errfileHandler);
} }
res.render('index.pug', TemplateVars); res.render('index.pug', TemplateVars);
masto_converter.conversion.fetchUserInfo();
}); });
masto_converter.conversion.fetchUserInfo(); masto_converter.conversion.fetchUserInfo();

View File

@ -1,6 +1,6 @@
{ {
"scripts": { "scripts": {
"start": "node main.js" "start": "nodemon main.js"
}, },
"dependencies": { "dependencies": {
"axios": "^0.19.2", "axios": "^0.19.2",

View File

@ -13,6 +13,7 @@ a {
padding: 0.5em; padding: 0.5em;
border-radius: 0.25em; border-radius: 0.25em;
border-bottom: 1px solid #42495c; border-bottom: 1px solid #42495c;
color: white;
} }
.published { .published {