script for meme bliss
This commit is contained in:
parent
0a53c63961
commit
e936dcc528
@ -1,36 +1,70 @@
|
||||
import fs from "fs";
|
||||
import path from 'path';
|
||||
import {getRandomElementOfArray, listFilesOfFolder, sendPostMastodon} from './utils.js'
|
||||
import {getRandomElementOfArray, listFilesOfFolder} from './utils.js'
|
||||
import Masto from "mastodon";
|
||||
|
||||
const __dirname = path.resolve();
|
||||
const list_unpublished_images = listFilesOfFolder('assets/pictures/meme/not_published')
|
||||
const folderMemeUnpublished = 'assets/pictures/meme/not_published'
|
||||
const list_unpublished_images = listFilesOfFolder(folderMemeUnpublished)
|
||||
|
||||
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){
|
||||
if (list_unpublished_images.length) {
|
||||
selectedImage = getRandomElementOfArray(list_unpublished_images)
|
||||
}else{
|
||||
console.log("----- nothing to publish -----")
|
||||
return;
|
||||
}
|
||||
console.log("selectedImage", selectedImage)
|
||||
let visibility = 'public';
|
||||
let language = 'fr';
|
||||
let sensitive = false;
|
||||
|
||||
let configPost = {
|
||||
author: 'meme',
|
||||
image: selectedImage,
|
||||
message: `
|
||||
#meme`,
|
||||
visibility,
|
||||
language,
|
||||
sensitive,
|
||||
status: `#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 )
|
||||
})
|
||||
console.log("configPost", configPost)
|
||||
let id = '';
|
||||
if (reallySendPost) {
|
||||
|
||||
|
||||
let accessToken = process.env['TOKEN_' + configPost.author.toUpperCase()]
|
||||
const masto = new Masto({
|
||||
access_token: accessToken,
|
||||
api_url: process.env.INSTANCE_MASTODON + '/api/v1/',
|
||||
});
|
||||
|
||||
masto.post('media', {file: fs.createReadStream( folderMemeUnpublished + configPost.image)})
|
||||
.then(resp => {
|
||||
id = resp.data.id;
|
||||
configPost.media_ids = [id]
|
||||
masto.post('statuses', configPost).then(rep => {
|
||||
// console.log('rep', rep)
|
||||
console.log(`posté avec une nouvelle image, ${configPost.image} WOOT`)
|
||||
console.log("post has been sent, time to move image from unpublished folder: ", selectedImage)
|
||||
}, err => {
|
||||
console.error(err)
|
||||
console.log("erreur T_T")
|
||||
})
|
||||
})
|
||||
} else {
|
||||
console.log("send post disabled for meme bliss")
|
||||
}
|
||||
}
|
||||
|
||||
postLink();
|
@ -144,7 +144,7 @@ export function sendPostMastodon(config) {
|
||||
* lister les noms de fichier que l'on peut publier dans un dossier.
|
||||
* retourne un tableau
|
||||
*/
|
||||
export function listFilesOfFolder(foldername){
|
||||
export function listFilesOfFolder(folderPath){
|
||||
let filesNames = []
|
||||
fs.readdirSync(folderPath).map(fileName => {
|
||||
return filesNames.push(fileName);
|
||||
|
Loading…
Reference in New Issue
Block a user