From fff69f31818882069aea196957f45797f6e404ad Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 21 Nov 2022 16:15:32 +0100 Subject: [PATCH] up qzine post --- README.md | 2 +- helpers/meme_poster_random.js | 2 +- helpers/{postQzine.js => postQzine.mjs} | 14 +++++++------- helpers/tkblogPost.js | 2 +- helpers/{utils.js => utils.mjs} | 2 +- helpers/wiki_osm.mjs | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) rename helpers/{postQzine.js => postQzine.mjs} (69%) rename helpers/{utils.js => utils.mjs} (99%) diff --git a/README.md b/README.md index 466fe6a..8c709c1 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ https://mastodon.cipherbliss.com ``` 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 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.js | 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 0 7 * * * su tykayn -c "bash /home/tykayn/wiki_osm.sh" */30 * * * * su tykayn -c "bash /home/tykayn/meme_poster_random.sh" diff --git a/helpers/meme_poster_random.js b/helpers/meme_poster_random.js index d088a0f..cce678f 100644 --- a/helpers/meme_poster_random.js +++ b/helpers/meme_poster_random.js @@ -1,6 +1,6 @@ import fs from "fs"; import path from 'path'; -import {getRandomElementOfArray, listFilesOfFolder} from './utils.js' +import {getRandomElementOfArray, listFilesOfFolder} from './utils.mjs' import Masto from "mastodon"; const __dirname = path.resolve(); diff --git a/helpers/postQzine.js b/helpers/postQzine.mjs similarity index 69% rename from helpers/postQzine.js rename to helpers/postQzine.mjs index b97d2c8..fc9bb66 100644 --- a/helpers/postQzine.js +++ b/helpers/postQzine.mjs @@ -1,9 +1,9 @@ import fs from "fs"; import path from 'path'; -import {sendPostMastodon} from './utils.js' +import sendPostMastodon from './utils.mjs' const __dirname = path.resolve(); -const list_posts_json = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/tykayn_qzinewp_posts.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 = true; @@ -14,16 +14,16 @@ export function getRandomElementOfArray(listItems) { function getRandomLink() { - let filteredLinks = list_posts_json.filter(elem => elem.post_status === 'publish') + let filteredLinks = list_posts_json.filter(elem => elem.status === 'publish') return getRandomElementOfArray(filteredLinks) } function postLink() { let postObject = getRandomLink() - console.log("envoi de post par le compte Qzine") + console.log("envoi de post par le compte Qzine - post n°" ,postObject.id) - let filteredExcerpt = postObject.post_content.replace(/<[^>]+>/g, '') + let filteredExcerpt = postObject.excerpt.rendered.replace(/<[^>]+>/g, '') let counterLength = filteredExcerpt.length; let limitExcerpt = 250 @@ -35,9 +35,9 @@ function postLink() { let configPost = { author: 'qzine', image: 'qzine_default.jpg', - message: `# [ !Qzine - ${postObject.post_title}](${postObject.guid}) + message: `# [ !Qzine - ${postObject.title.rendered}](${postObject.link}) -* ${postObject.post_date} - ${postObject.guid} +* ${postObject.date} - ${postObject.link} ${filteredExcerpt} * #qzine #qzineblog #blog #sexe #relations #éducation #plaisir #sociologie`, reallySendPost diff --git a/helpers/tkblogPost.js b/helpers/tkblogPost.js index 9376f69..83b20fd 100644 --- a/helpers/tkblogPost.js +++ b/helpers/tkblogPost.js @@ -1,7 +1,7 @@ import fs from "fs"; import path from 'path'; -import {sendPostMastodon} from './utils.js' +import {sendPostMastodon} from './utils.mjs' const __dirname = path.resolve(); const tkpostsjson = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/tykayn_wptkblog_posts.json", 'utf-8')) diff --git a/helpers/utils.js b/helpers/utils.mjs similarity index 99% rename from helpers/utils.js rename to helpers/utils.mjs index fd26064..791466b 100644 --- a/helpers/utils.js +++ b/helpers/utils.mjs @@ -34,7 +34,7 @@ export function tokenForAuthorIsPresentInDotEnv(author) { return process.env['TOKEN_' + author.toUpperCase()]; } -export function sendPostMastodon(config) { +export default function sendPostMastodon(config){ // override defaults with input argument config = { diff --git a/helpers/wiki_osm.mjs b/helpers/wiki_osm.mjs index 7633a0d..3192b74 100644 --- a/helpers/wiki_osm.mjs +++ b/helpers/wiki_osm.mjs @@ -7,7 +7,7 @@ import rp from "request-promise"; import $ from "cheerio"; import fs from "fs"; import path from 'path'; -import {randomIntFromInterval, sendPostMastodon} from "./utils.js"; +import {randomIntFromInterval, sendPostMastodon} from "./utils.mjs"; const __dirname = path.resolve();