add meme poster
BIN
assets/pictures/meme/not_published/bambi.jpg
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
assets/pictures/meme/not_published/cat_spray.jpg
Executable file
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 69 KiB |
BIN
assets/pictures/meme/not_published/courge_musquee_butternut.png
Executable file
After Width: | Height: | Size: 165 KiB |
BIN
assets/pictures/meme/not_published/e3fbbdda01292e42.jpg
Executable file
After Width: | Height: | Size: 178 KiB |
BIN
assets/pictures/meme/not_published/f3edd377aaf09702.jpg
Executable file
After Width: | Height: | Size: 54 KiB |
BIN
assets/pictures/meme/not_published/f433bb1e9e3bcf1c.png
Executable file
After Width: | Height: | Size: 298 KiB |
BIN
assets/pictures/meme/not_published/f59b9550653d68a8.jpg
Executable file
After Width: | Height: | Size: 60 KiB |
36
helpers/meme_poster_random.js
Normal 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();
|
@ -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);
|
||||
}
|
||||
}
|