67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
import fs from "fs";
|
|
import path from 'path';
|
|
import sendPostMastodon, {
|
|
randomIntFromInterval,
|
|
getRandomElementOfArray,
|
|
findPictureAndSendPost
|
|
} from './utils.mjs'
|
|
|
|
const folderBlogPostsPreview = process.cwd() + '/assets/blog_posts_medias/'
|
|
|
|
/**
|
|
*
|
|
* 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 list_posts_json = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/qzine_posts_all.json", 'utf-8'))
|
|
let reallySendPost = false;
|
|
// reallySendPost = true;
|
|
|
|
|
|
function getRandomLinkQzine() {
|
|
let filteredLinks = list_posts_json.filter(elem => elem.status === 'publish')
|
|
return getRandomElementOfArray(filteredLinks)
|
|
}
|
|
|
|
function postLink() {
|
|
|
|
let postObject = getRandomLinkQzine()
|
|
console.log("envoi de post par le compte Qzine - post n°" ,postObject.id)
|
|
|
|
let filteredExcerpt = postObject.excerpt.rendered.replace(/<[^>]+>/g, '')
|
|
let counterLength = filteredExcerpt.length;
|
|
|
|
let limitExcerpt = 250
|
|
filteredExcerpt = filteredExcerpt.substring(0, limitExcerpt)
|
|
if (filteredExcerpt && counterLength > limitExcerpt) {
|
|
filteredExcerpt = '> ' + filteredExcerpt + '… '
|
|
}
|
|
|
|
let configPost = {
|
|
author: 'qzine',
|
|
website: 'qzine',
|
|
slug: postObject.title.rendered,
|
|
postObject,
|
|
folder_image: folderBlogPostsPreview,
|
|
image: 'qzine_post_' + randomIntFromInterval(1 , 4) + '.jpg',
|
|
message: `!Qzine - ${postObject.title.rendered}
|
|
|
|
* ${postObject.link}
|
|
${filteredExcerpt}
|
|
* #qzine #qzineblog #blog #sexe #relations #éducation #plaisir #sociologie`,
|
|
reallySendPost
|
|
}
|
|
|
|
// console.log('postContent' , postContent)
|
|
findPictureAndSendPost(postObject.content.rendered, configPost)
|
|
}
|
|
|
|
postLink(); |