From 5f7231ca68537541166bb02ae6a9f9e4862d372d Mon Sep 17 00:00:00 2001 From: Tykayn Date: Sat, 4 Mar 2023 10:30:20 +0100 Subject: [PATCH] gather mentions of multi accounts --- .env.example | 5 -- .gitignore | 3 +- app.js => app.mjs | 2 +- assets/bash_scripts/get_mentions_multi.sh | 3 + cron_scripts/crontab | 2 + helpers/configs.js | 42 ++++++++++++++ helpers/get_mentions.mjs | 67 +++++++++++++++++++++++ helpers/utils.mjs | 13 +++++ routes/index.js | 5 +- routes/mentions.js | 28 ++++++++++ views/mentions.jade | 8 +++ 11 files changed, 170 insertions(+), 8 deletions(-) rename app.js => app.mjs (93%) create mode 100644 assets/bash_scripts/get_mentions_multi.sh create mode 100644 helpers/configs.js create mode 100644 helpers/get_mentions.mjs create mode 100644 routes/mentions.js create mode 100644 views/mentions.jade diff --git a/.env.example b/.env.example index a138ef0..10a06ed 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,4 @@ -APP_ID=ABCD -SECRET=ABCD -TOKEN=ABCD APP_NAME="autopost bot" INSTANCE_MASTODON="https://mastodon.cipherbliss.com" - TOKEN_account_A=ABCD - TOKEN_account_B=ABCD diff --git a/.gitignore b/.gitignore index 375c8cd..183dcda 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ mastodon_multi_accounts.db assets/pictures/meme/not_published/* assets/pictures/meme/published/* #!/assets/documents/qzine_posts_all.json -assets/blog_posts_medias/* \ No newline at end of file +assets/blog_posts_medias/* +/bin/mentions.html diff --git a/app.js b/app.mjs similarity index 93% rename from app.js rename to app.mjs index e00d7f9..41d7fb8 100644 --- a/app.js +++ b/app.mjs @@ -44,6 +44,6 @@ module.exports = app; app.listen(listenPort, () => console.log(`Server is live at http://localhost:${listenPort}`)); console.log('================================================================='); -console.log('made by Tykayn from CipherBliss - https://mastodon.cipherbliss.com/@tykayn'); +console.log('= made by Tykayn from CipherBliss - https://mastodon.cipherbliss.com/@tykayn'); console.log('================================================================='); diff --git a/assets/bash_scripts/get_mentions_multi.sh b/assets/bash_scripts/get_mentions_multi.sh new file mode 100644 index 0000000..3aabce3 --- /dev/null +++ b/assets/bash_scripts/get_mentions_multi.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +node helpers/get_mentions.mjs > bin/mentions.ht diff --git a/cron_scripts/crontab b/cron_scripts/crontab index bb93766..c2d6298 100644 --- a/cron_scripts/crontab +++ b/cron_scripts/crontab @@ -10,5 +10,7 @@ 0 9 * * * bash /home/tykayn/www/multi-account-post-schedule-mastodon/assets/bash_scripts/osm_wiki.sh | tee -a /home/tykayn/log_autopost.txt 2>&1 # tous les Vendredis à midi, revue de lecture AFIS +0 5 * * 4 bash /home/tykayn/www/multi-account-post-schedule-mastodon/assets/bash_scripts/agendadulibre_coming_osm.sh | tee -a /home/tykayn/log_autopost.txt 2>&1 0 12 * * 5 bash /home/tykayn/www/multi-account-post-schedule-mastodon/assets/bash_scripts/afis_science.sh | tee -a /home/tykayn/log_autopost.txt 2>&1 +0 6 * * 6 bash /home/tykayn/www/multi-account-post-schedule-mastodon/assets/bash_scripts/idf_agendadulibre.sh | tee -a /home/tykayn/log_autopost.txt 2>&1 # ----------- END mastodon autopost ------------- \ No newline at end of file diff --git a/helpers/configs.js b/helpers/configs.js new file mode 100644 index 0000000..5f77943 --- /dev/null +++ b/helpers/configs.js @@ -0,0 +1,42 @@ +export const accounts_to_select = [ + { + label: "tykayn", + value: "tykayn", + src : "https://mastodon.cipherbliss.com/system/accounts/avatars/000/000/001/original/6388tykayn.gif" + }, + { + label: "modominem", + value: "modominem", + src : "https://mastodon.cipherbliss.com/system/accounts/avatars/000/152/770/original/c62bb94381dc1f75.png" + }, + { + label: "qzine", + value: "qzine", + src :"https://mastodon.cipherbliss.com/system/accounts/avatars/000/003/032/original/2bb8b90d21d3fdca.jpg" + }, + { + label: "curator", + value: "curator", + src : "https://mastodon.cipherbliss.com/system/accounts/avatars/000/002/974/original/8e48623291e49afe.jpg" + }, + { + label: "kurator", + value: "kurator", + src : "https://mastodon.cipherbliss.com/system/accounts/avatars/000/162/067/original/bb374d2c6a361b6d.jpg" + }, + { + label: "voix du nucléaire", + value: "voixdunucleaire", + src : "https://mastodon.cipherbliss.com/system/accounts/avatars/000/107/055/original/7dac1a35f1423b94.jpg" + }, + { + label: "The greatest Meme", + value: "meme", + src : "https://mastodon.cipherbliss.com/system/accounts/avatars/000/002/978/original/b2f2e817572c93e9.png" + }, + { + label: "cil de gometz", + value: "cil_gometz", + src : "https://mastodon.cipherbliss.com/system/accounts/avatars/000/107/055/original/7dac1a35f1423b94.jpg" + }, +] \ No newline at end of file diff --git a/helpers/get_mentions.mjs b/helpers/get_mentions.mjs new file mode 100644 index 0000000..5e10440 --- /dev/null +++ b/helpers/get_mentions.mjs @@ -0,0 +1,67 @@ +import {createMastoFetcherWithAuthorLogin} from "./utils.mjs"; +import moment from 'moment' + +moment.locale('fr') + +console.log('' + + '' + + '' + + + '' + + '' + + '.avatar{ margin-right: 1em; margin-bottom: 1em; width: 4rem; height: 4rem;}'+ + '') +console.log('get mentions on all accounts managed') + + +export async function getMentionsOfAccount(accountToFetch) { + + const masto = createMastoFetcherWithAuthorLogin(accountToFetch) + let results = {} + + results = await masto.get('notifications??exclude_types[]=follow&exclude_types[]=follow_request&exclude_types[]=favourite&exclude_types[]=reblog&exclude_types[]=poll&exclude_types[]=status&exclude_types[]=update&exclude_types[]=admin.sign_up&exclude_types[]=admin.report') + +// console.log('results',results) + console.log('
# mentions du compte ' + accountToFetch) + results.data.forEach(item => { + if(item.type !=='follow'){ + + // if(item.type =='mention'){ + // console.log('item', item) + console.log('\n
from ', item.account.username, '') + // console.log('in reply to ', item.status.in_reply_to_id ) + // console.log('language', item.status.language ) + if (item.status) { + console.log(` + lien`) + console.log('\n : ',item.type,' :', moment(item.status.created_at).format('dddd YYYY-MM-DD HH:ii:ss')) + console.log('\n
', item.status.content, '
') + } + else{ + console.log('
',item,'
') + console.log('') + } + console.log('
') + } + // } + }) + console.log('
\n
') + +} + +const accounts = [ + 'qzine', + // 'tykayn', + // 'curator', + // 'modominem', + 'voixdunucleaire', + // 'voicesofnuclear', + 'afis91' +] + +accounts.forEach(item => getMentionsOfAccount(item)) +console.log('') +console.log('') \ No newline at end of file diff --git a/helpers/utils.mjs b/helpers/utils.mjs index 67d5044..bd80780 100644 --- a/helpers/utils.mjs +++ b/helpers/utils.mjs @@ -44,6 +44,19 @@ export function tokenForAuthorIsPresentInDotEnv(author) { return process.env['TOKEN_' + author.toUpperCase()]; } +/** + * create a masto fetcher instance + * @param userNickName + * @returns {Mastodon} + */ +export function createMastoFetcherWithAuthorLogin(userNickName){ + let accessToken = process.env['TOKEN_' + userNickName.toUpperCase()] + const masto = new Masto({ + access_token: accessToken, + api_url: process.env.INSTANCE_MASTODON + '/api/v1/', + }); + return masto; +} /** * send post to mastodon with config * @param config diff --git a/routes/index.js b/routes/index.js index 749babd..74e1cb9 100644 --- a/routes/index.js +++ b/routes/index.js @@ -2,7 +2,8 @@ var express = require('express'); var router = express.Router(); var sqlite3 = require('sqlite3'); var Masto = require('mastodon'); -// change this object to fit your multi accounts +// import accounts_to_select from '../src/configs.js' + const accounts_to_select = [ { label: "tykayn", @@ -45,6 +46,8 @@ const accounts_to_select = [ src : "https://mastodon.cipherbliss.com/system/accounts/avatars/000/107/055/original/7dac1a35f1423b94.jpg" }, ] + +// change this object to fit your multi accounts const default_times = ['08:02:00', '08:42:00', '09:10:00', '09:15:00', '10:22:00', '12:22:00'] const database_masto = "mastodon_multi_accounts.db" /* GET home page. */ diff --git a/routes/mentions.js b/routes/mentions.js new file mode 100644 index 0000000..cfaf923 --- /dev/null +++ b/routes/mentions.js @@ -0,0 +1,28 @@ +import accounts_to_select from "../src/configs"; + +var express = require('express'); +var router = express.Router(); +const Masto = require('mastodon'); + +/* GET users listing. */ +router.get('/', function(req, res, next) { + + + + module.exports.toot = async ({accessToken, status, visibility, file}) => { + const masto = new Masto({/* w w w . d em o 2s . c o m */ + access_token: accessToken, + api_url: process.env.INSTANCE_MASTODON+'/api/v1/', + }); + + return masto.get('notifications', { + type : "mention" + }); + }; + + // res.send('private messages'); + res.render('mentions', {accounts_to_select, reqBody: req.body, }); + +}); + +module.exports = router; diff --git a/views/mentions.jade b/views/mentions.jade new file mode 100644 index 0000000..3e77264 --- /dev/null +++ b/views/mentions.jade @@ -0,0 +1,8 @@ +extends layout + +block content + h1 "Mentions des comptes" + div.accounts + ul + li "un compte" + .mention