add meme poster

This commit is contained in:
Tykayn 2022-08-08 22:49:12 +02:00 committed by tykayn
parent 6a1821bfaf
commit 0a53c63961
10 changed files with 63 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

View File

@ -0,0 +1,36 @@
import fs from "fs";
import path from 'path';
import {getRandomElementOfArray, listFilesOfFolder, sendPostMastodon} from './utils.js'
const __dirname = path.resolve();
const list_unpublished_images = listFilesOfFolder('assets/pictures/meme/not_published')
const reallySendPost = false;
// const reallySendPost = true;
function postLink() {
let postObject = getRandomLink()
console.log("envoi de post par le compte meme bliss")
let selectedImage = 'meme_default.jpg';
if(list_unpublished_images.length){
selectedImage = getRandomElementOfArray(list_unpublished_images)
}
let configPost = {
author: 'meme',
image: selectedImage,
message: `
#meme`,
reallySendPost
}
console.log("configPost.message", configPost.message)
sendPostMastodon(configPost).finally(data => {
console.log("post has been sent, time to move image from unpublished folder: " ,selectedImage )
})
}
postLink();

View File

@ -139,4 +139,31 @@ export function sendPostMastodon(config) {
}
}
/**
* @name listFilesOfFolder
* lister les noms de fichier que l'on peut publier dans un dossier.
* retourne un tableau
*/
export function listFilesOfFolder(foldername){
let filesNames = []
fs.readdirSync(folderPath).map(fileName => {
return filesNames.push(fileName);
});
return filesNames;
}
/**
* @name initializeFolderForPictures
* crée un dossier d'assets, avec ses sous dossiers not_published et published si ils manquent.
* une fois que l'on prendra une image dans le dossier non publié, on la déplacera dans le dossier des images publées.
*/
export function initializeFolderForPictures(folderName){
try {
if (!fs.existsSync(folderName)) {
fs.mkdirSync(folderName);
}
} catch (err) {
console.error(err);
}
}