diff --git a/assets/pictures/meme/not_published/bambi.jpg b/assets/pictures/meme/not_published/bambi.jpg new file mode 100644 index 0000000..f41e455 Binary files /dev/null and b/assets/pictures/meme/not_published/bambi.jpg differ diff --git a/assets/pictures/meme/not_published/cat_spray.jpg b/assets/pictures/meme/not_published/cat_spray.jpg new file mode 100755 index 0000000..da2ee5d Binary files /dev/null and b/assets/pictures/meme/not_published/cat_spray.jpg differ diff --git a/assets/pictures/meme/not_published/cat_who_doesnt_feel_so_good.jpg b/assets/pictures/meme/not_published/cat_who_doesnt_feel_so_good.jpg new file mode 100644 index 0000000..3b021bc Binary files /dev/null and b/assets/pictures/meme/not_published/cat_who_doesnt_feel_so_good.jpg differ diff --git a/assets/pictures/meme/not_published/courge_musquee_butternut.png b/assets/pictures/meme/not_published/courge_musquee_butternut.png new file mode 100755 index 0000000..0683019 Binary files /dev/null and b/assets/pictures/meme/not_published/courge_musquee_butternut.png differ diff --git a/assets/pictures/meme/not_published/e3fbbdda01292e42.jpg b/assets/pictures/meme/not_published/e3fbbdda01292e42.jpg new file mode 100755 index 0000000..ce2f993 Binary files /dev/null and b/assets/pictures/meme/not_published/e3fbbdda01292e42.jpg differ diff --git a/assets/pictures/meme/not_published/f3edd377aaf09702.jpg b/assets/pictures/meme/not_published/f3edd377aaf09702.jpg new file mode 100755 index 0000000..df01593 Binary files /dev/null and b/assets/pictures/meme/not_published/f3edd377aaf09702.jpg differ diff --git a/assets/pictures/meme/not_published/f433bb1e9e3bcf1c.png b/assets/pictures/meme/not_published/f433bb1e9e3bcf1c.png new file mode 100755 index 0000000..e378ff7 Binary files /dev/null and b/assets/pictures/meme/not_published/f433bb1e9e3bcf1c.png differ diff --git a/assets/pictures/meme/not_published/f59b9550653d68a8.jpg b/assets/pictures/meme/not_published/f59b9550653d68a8.jpg new file mode 100755 index 0000000..9ea2a69 Binary files /dev/null and b/assets/pictures/meme/not_published/f59b9550653d68a8.jpg differ diff --git a/helpers/meme_poster_random.js b/helpers/meme_poster_random.js new file mode 100644 index 0000000..10b3ade --- /dev/null +++ b/helpers/meme_poster_random.js @@ -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(); \ No newline at end of file diff --git a/helpers/utils.js b/helpers/utils.js index 9db00ff..0d5fea8 100644 --- a/helpers/utils.js +++ b/helpers/utils.js @@ -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); + } +} \ No newline at end of file