ajout de random dans les images de post, ajout script posts de cipherbliss
This commit is contained in:
parent
f28e1b9f34
commit
bf0af80878
25
README.md
25
README.md
@ -1,11 +1,32 @@
|
|||||||
# Mastodon Multi account posting
|
# Mastodon Multi account posting
|
||||||
|
|
||||||
Permet de poster sur mastodon selon le compte que l'on souhaite
|
Permet de poster sur mastodon selon le compte que l'on souhaite
|
||||||
multi-account-post-schedule-mastodon
|
multi-account-post-schedule-mastodon et de réaliser des bots d'autopost de liens et d'images.
|
||||||
|
|
||||||
Pouvoir faire de la planification de posts de plusieurs comptes mastodon en créant une app pour chacun d'eux dans son compte masto, et en reportant les accès dans un fichier d'environnement de cette app nodejs.
|
Pouvoir faire de la planification de posts de plusieurs comptes mastodon en créant une app pour chacun d'eux dans son compte masto, et en reportant les accès dans un fichier d'environnement de cette app nodejs.
|
||||||
![screenshot form](assets/screenshot_form.png)
|
![screenshot form](assets/screenshot_form.png)
|
||||||
# Getting started
|
# Getting started
|
||||||
|
## Scripts d'autopost
|
||||||
|
Utiliser un cronjob pour lancer les scripts bash, qui s'occupent de faire fonctionner les scripts JS avec les bonnes variables d'environnement.
|
||||||
|
Voir le dossier [cron_scripts](cron_scripts) montrant un exemple de crontab.
|
||||||
|
Modifiez votre crontab avec votre éditeur préféré en ligne de commande:
|
||||||
|
```bash
|
||||||
|
crontab -e
|
||||||
|
```
|
||||||
|
### Remplir les variables du fichier .env à créer
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
```
|
||||||
|
Et ajoutez les token de bot pour faire de l'autopost. Vous trouverez ces token dans vos comptes d'utilisateur Mastodon, partie "développement", créer un token pour chaque compte.
|
||||||
|
```dotenv
|
||||||
|
TOKEN_account_UTILISATEUR_MACHIN=MON_TOKEN_SDZERTYYRUTKIOUL46577OUKI?FXGDSGTGH_EXEMPLE
|
||||||
|
```
|
||||||
|
|
||||||
|
Installez les dépendances NPM avec Yarn.
|
||||||
|
Récupérez les fichiers de blog wordpress via l'interface wp-json, mettez les json dans le dossier source.
|
||||||
|
Modifiez les scripts dans le dossier helpers pour les faire convenir à votre présentation de Toot Mastodn.
|
||||||
|
Exécutez les scripts node.
|
||||||
|
## Interface Web multi compte
|
||||||
Requirements: avoir nodeJS sur sa machine et un navigateur.
|
Requirements: avoir nodeJS sur sa machine et un navigateur.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -64,7 +85,7 @@ https://mastodon.cipherbliss.com
|
|||||||
# Cronjob
|
# Cronjob
|
||||||
|
|
||||||
```
|
```
|
||||||
12 12-14 * * * cd /home/tykayn/www/mastodon_multi_account && nvm use 16 && node helpers/tkblogPost.js | tee -a /home/tykayn/log_autopost.txt 2>&1
|
12 12-14 * * * cd /home/tykayn/www/mastodon_multi_account && nvm use 16 && node helpers/tkblogPost.mjs | tee -a /home/tykayn/log_autopost.txt 2>&1
|
||||||
0 7 * * * cd /home/tykayn/www/mastodon_multi_account && nvm use 16 && node helpers/wiki_osm.mjs | tee -a /home/tykayn/log_autopost.txt 2>&1
|
0 7 * * * cd /home/tykayn/www/mastodon_multi_account && nvm use 16 && node helpers/wiki_osm.mjs | tee -a /home/tykayn/log_autopost.txt 2>&1
|
||||||
0 0 * * * cd /home/tykayn/www/mastodon_multi_account && nvm use 16 && node helpers/postQzine.mjs | tee -a /home/tykayn/log_autopost.txt 2>&1
|
0 0 * * * cd /home/tykayn/www/mastodon_multi_account && nvm use 16 && node helpers/postQzine.mjs | tee -a /home/tykayn/log_autopost.txt 2>&1
|
||||||
# version avec scripts bash
|
# version avec scripts bash
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
nvm use 16
|
nvm use 16
|
||||||
cd /home/tykayn/www/mastodon_multi_account
|
cd /home/tykayn/www/mastodon_multi_account
|
||||||
node helpers/postQzine.js | tee -a /home/tykayn/log_autopost.txt 2>&1
|
node helpers/postQzine.mjs | tee -a /home/tykayn/log_autopost.txt 2>&1
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
nvm use 16
|
nvm use 16
|
||||||
cd /home/tykayn/www/mastodon_multi_account
|
cd /home/tykayn/www/mastodon_multi_account
|
||||||
node helpers/tkblogPost.js | tee -a /home/tykayn/log_autopost.txt 2>&1
|
node helpers/tkblogPost.mjs | tee -a /home/tykayn/log_autopost.txt 2>&1
|
||||||
|
BIN
assets/cipherbliss_post_1.jpg
Executable file
BIN
assets/cipherbliss_post_1.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 149 KiB |
BIN
assets/cipherbliss_post_2.jpg
Normal file
BIN
assets/cipherbliss_post_2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 72 KiB |
BIN
assets/cipherbliss_post_3.jpg
Executable file
BIN
assets/cipherbliss_post_3.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 187 KiB |
51
helpers/cipherbliss_post.mjs
Normal file
51
helpers/cipherbliss_post.mjs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import fs from "fs";
|
||||||
|
import path from 'path';
|
||||||
|
import sendPostMastodon, {randomIntFromInterval, findFirstImageInContent} from './utils.mjs'
|
||||||
|
|
||||||
|
const __dirname = path.resolve();
|
||||||
|
const tkpostsjson = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/cipherbliss_tkwp_posts.json", 'utf-8'))
|
||||||
|
const reallySendPost = false;
|
||||||
|
// const reallySendPost = true;
|
||||||
|
|
||||||
|
|
||||||
|
export function getRandomElementOfArray(listItems) {
|
||||||
|
return listItems[Math.floor(Math.random() * listItems.length)]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getRandomLink() {
|
||||||
|
let filteredLinks = tkpostsjson.filter(elem => elem.post_status === 'publish')
|
||||||
|
return getRandomElementOfArray(filteredLinks)
|
||||||
|
}
|
||||||
|
|
||||||
|
function postLink() {
|
||||||
|
|
||||||
|
let postObject = getRandomLink()
|
||||||
|
console.log("envoi de post de blog cipherbliss par le compte tykayn")
|
||||||
|
|
||||||
|
let filteredExcerpt = postObject.post_content.replace(/<[^>]+>/g, '')
|
||||||
|
let counterLength = filteredExcerpt.length;
|
||||||
|
|
||||||
|
let limitExcerpt = 250
|
||||||
|
filteredExcerpt = filteredExcerpt.substring(0, limitExcerpt)
|
||||||
|
if (filteredExcerpt && counterLength > limitExcerpt) {
|
||||||
|
filteredExcerpt = ' _ ' + filteredExcerpt + '… _'
|
||||||
|
}
|
||||||
|
|
||||||
|
let configPost = {
|
||||||
|
author: 'tykayn',
|
||||||
|
image: 'cipherbliss_post_' + randomIntFromInterval(1 - 3) + '.jpg',
|
||||||
|
message: `# [${postObject.post_title}](${postObject.guid})
|
||||||
|
|
||||||
|
* ${postObject.post_date} - ${postObject.guid}
|
||||||
|
${filteredExcerpt}
|
||||||
|
* #tykayn #cipherbliss #blog`,
|
||||||
|
reallySendPost
|
||||||
|
}
|
||||||
|
console.log("configPost.message", configPost.message)
|
||||||
|
|
||||||
|
findFirstImageInContent(postObject.post_content)
|
||||||
|
sendPostMastodon(configPost)
|
||||||
|
}
|
||||||
|
|
||||||
|
postLink();
|
88
helpers/curation_image_random.mjs
Normal file
88
helpers/curation_image_random.mjs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
import fs from "fs";
|
||||||
|
import path from 'path';
|
||||||
|
import {getRandomElementOfArray, listFilesOfFolder} from './utils.mjs'
|
||||||
|
import Masto from "mastodon";
|
||||||
|
|
||||||
|
const __dirname = path.resolve();
|
||||||
|
|
||||||
|
// choisir un type de publication au hasard dans les dossiers "picture"
|
||||||
|
|
||||||
|
import pictureFolderDescriptions from "./describe_picture_folders.mjs"
|
||||||
|
const typeOfFolder = getRandomElementOfArray(Object.keys(pictureFolderDescriptions))
|
||||||
|
|
||||||
|
console.log(typeOfFolder)
|
||||||
|
|
||||||
|
const folderMemeUnpublished = 'assets/pictures/meme/not_published/'
|
||||||
|
const folderMemePublished = 'assets/pictures/meme/published/'
|
||||||
|
const list_unpublished_images = listFilesOfFolder(folderMemeUnpublished)
|
||||||
|
|
||||||
|
const reallySendPost = false;
|
||||||
|
// const reallySendPost = true;
|
||||||
|
|
||||||
|
|
||||||
|
function postLink() {
|
||||||
|
|
||||||
|
console.log("envoi de post par le compte curator")
|
||||||
|
|
||||||
|
|
||||||
|
let selectedImage = 'meme_default.jpg';
|
||||||
|
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,
|
||||||
|
visibility,
|
||||||
|
language,
|
||||||
|
sensitive,
|
||||||
|
status: `#meme`,
|
||||||
|
reallySendPost
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
moveImageToPublishedFolder(selectedImage)
|
||||||
|
}, err => {
|
||||||
|
console.error(err)
|
||||||
|
console.log("erreur T_T")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.log("send post disabled for meme bliss")
|
||||||
|
console.log("image", configPost.image)
|
||||||
|
console.log("image NON envoyée")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* move to published
|
||||||
|
* @param imageName
|
||||||
|
*/
|
||||||
|
function moveImageToPublishedFolder(imageName){
|
||||||
|
return fs.renameSync(folderMemeUnpublished + imageName, folderMemePublished + imageName)
|
||||||
|
}
|
||||||
|
postLink();
|
@ -17,5 +17,9 @@ export default {
|
|||||||
name: 'memes',
|
name: 'memes',
|
||||||
descriptions: 'meme'
|
descriptions: 'meme'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'inspiration',
|
||||||
|
descriptions: 'inspiration'
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -8,8 +8,8 @@ const folderMemeUnpublished = 'assets/pictures/meme/not_published/'
|
|||||||
const folderMemePublished = 'assets/pictures/meme/published/'
|
const folderMemePublished = 'assets/pictures/meme/published/'
|
||||||
const list_unpublished_images = listFilesOfFolder(folderMemeUnpublished)
|
const list_unpublished_images = listFilesOfFolder(folderMemeUnpublished)
|
||||||
|
|
||||||
// const reallySendPost = false;
|
const reallySendPost = false;
|
||||||
const reallySendPost = true;
|
// const reallySendPost = true;
|
||||||
|
|
||||||
|
|
||||||
function postLink() {
|
function postLink() {
|
||||||
@ -65,6 +65,8 @@ function postLink() {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log("send post disabled for meme bliss")
|
console.log("send post disabled for meme bliss")
|
||||||
|
console.log("image", configPost.image)
|
||||||
|
console.log("image NON envoyée")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,18 @@ import fs from "fs";
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import sendPostMastodon from './utils.mjs'
|
import sendPostMastodon from './utils.mjs'
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Poster une image au hasard, et la déplacer dans le dossier "publiés"
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupérer les json avec ces url
|
||||||
|
* https://qzine.fr/wp-json/wp/v2/posts?per_page=100&page=1
|
||||||
|
* https://qzine.fr/wp-json/wp/v2/posts?per_page=100&page=2
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
const __dirname = path.resolve();
|
const __dirname = path.resolve();
|
||||||
const list_posts_json = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/qzine_posts_all.json", 'utf-8'))
|
const list_posts_json = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/qzine_posts_all.json", 'utf-8'))
|
||||||
// const reallySendPost = false;
|
// const reallySendPost = false;
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {randomIntFromInterval, sendPostMastodon} from './utils.mjs'
|
import sendPostMastodon, {randomIntFromInterval} from './utils.mjs'
|
||||||
|
|
||||||
const __dirname = path.resolve();
|
const __dirname = path.resolve();
|
||||||
const tkpostsjson = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/tykayn_wptkblog_posts.json", 'utf-8'))
|
const tkpostsjson = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/tykayn_wptkblog_posts.json", 'utf-8'))
|
||||||
// const reallySendPost = false;
|
const reallySendPost = false;
|
||||||
const reallySendPost = true;
|
// const reallySendPost = true;
|
||||||
|
|
||||||
|
|
||||||
export function getRandomElementOfArray(listItems) {
|
export function getRandomElementOfArray(listItems) {
|
||||||
@ -35,7 +34,7 @@ function postLink() {
|
|||||||
|
|
||||||
let configPost = {
|
let configPost = {
|
||||||
author: 'tykayn',
|
author: 'tykayn',
|
||||||
image: 'tk_blog_bannieres_oct2010-'+randomIntFromInterval(1-10)+'.jpg',
|
image: 'tk_blog_bannieres_oct2010-' + randomIntFromInterval(1 - 10) + '.jpg',
|
||||||
message: `# [${postObject.post_title}](${postObject.guid})
|
message: `# [${postObject.post_title}](${postObject.guid})
|
||||||
|
|
||||||
* ${postObject.post_date} - ${postObject.guid}
|
* ${postObject.post_date} - ${postObject.guid}
|
@ -1,13 +1,14 @@
|
|||||||
import Masto from "mastodon";
|
import Masto from "mastodon";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import fs from "node-fs";
|
import fs from "node-fs";
|
||||||
|
import $, {html} from "cheerio";
|
||||||
|
|
||||||
let local_node_env_conf = dotenv.config()
|
let local_node_env_conf = dotenv.config()
|
||||||
|
|
||||||
// console.log("conf", local_node_env_conf)
|
// console.log("conf", local_node_env_conf)
|
||||||
|
|
||||||
export function randomIntFromInterval(min, max) { // min and max included
|
export function randomIntFromInterval(min, max) { // min and max included
|
||||||
return Math.floor(Math.random() * (max - min + 1) + min)
|
return Math.floor(Math.random() * (max - min + 1) + min) | 1
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRandomElementOfArray(listItems) {
|
export function getRandomElementOfArray(listItems) {
|
||||||
@ -167,3 +168,10 @@ export function initializeFolderForPictures(folderName){
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function findFirstImageInContent(htmlContent){
|
||||||
|
let firstImgSource = ''
|
||||||
|
|
||||||
|
let img = $(htmlContent).find('img')
|
||||||
|
return firstImgSource;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user