gather mentions of multi accounts

This commit is contained in:
Tykayn 2023-03-04 10:30:20 +01:00 committed by tykayn
parent ae33a57bf4
commit 5f7231ca68
11 changed files with 170 additions and 8 deletions

View File

@ -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

3
.gitignore vendored
View File

@ -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/*
assets/blog_posts_medias/*
/bin/mentions.html

View File

@ -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('=================================================================');

View File

@ -0,0 +1,3 @@
#!/bin/bash
node helpers/get_mentions.mjs > bin/mentions.ht

View File

@ -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 -------------

42
helpers/configs.js Normal file
View File

@ -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"
},
]

67
helpers/get_mentions.mjs Normal file
View File

@ -0,0 +1,67 @@
import {createMastoFetcherWithAuthorLogin} from "./utils.mjs";
import moment from 'moment'
moment.locale('fr')
console.log('<html>' +
'<head>' +
'<meta charset="utf-8"/>' +
'</head><body>' +
'<style>' +
'body{ width:80vw, padding: 2rem; margin: 0 auto; font-family: Arial, sans-serif; font-size: 1.5rem;}' +
'.block_account{ padding: 1.5rem;}' +
'.message{ padding: 1rem 2rem;}</style>' +
'.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('<div class="block_account"> # mentions du compte ' + accountToFetch)
results.data.forEach(item => {
if(item.type !=='follow'){
// if(item.type =='mention'){
// console.log('item', item)
console.log('\n <div class="message">from <strong>', item.account.username, '</strong>')
// console.log('in reply to ', item.status.in_reply_to_id )
// console.log('language', item.status.language )
if (item.status) {
console.log(`
<a href="${item.status.uri}">lien</a>`)
console.log('\n : ',item.type,' :', moment(item.status.created_at).format('dddd YYYY-MM-DD HH:ii:ss'))
console.log('\n <blockquote>', item.status.content, '</blockquote>')
}
else{
console.log('<pre>',item,'</pre>')
console.log('<img class="avatar" src="',item.account.avatar_static,'">')
}
console.log('</div>')
}
// }
})
console.log('</div>\n <hr>')
}
const accounts = [
'qzine',
// 'tykayn',
// 'curator',
// 'modominem',
'voixdunucleaire',
// 'voicesofnuclear',
'afis91'
]
accounts.forEach(item => getMentionsOfAccount(item))
console.log('</body>')
console.log('</html>')

View File

@ -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

View File

@ -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. */

28
routes/mentions.js Normal file
View File

@ -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;

8
views/mentions.jade Normal file
View File

@ -0,0 +1,8 @@
extends layout
block content
h1 "Mentions des comptes"
div.accounts
ul
li "un compte"
.mention