This commit is contained in:
Tykayn 2025-01-12 15:03:07 +01:00 committed by tykayn
parent a85b9fd7ee
commit 7ef228aa49
7 changed files with 18782 additions and 2 deletions

View File

@ -1 +0,0 @@
bash: /home/cipherbliss/Téléchargements/WebStorm-232.10335.13/bin/bin/webstorm.sh: Aucun fichier ou dossier de ce nom

View File

@ -0,0 +1 @@

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -71,6 +71,7 @@ input.button {
.account__avatar-overlay { .account__avatar-overlay {
border: solid 3px transparent; border: solid 3px transparent;
width: 5em;
} }
.account__avatar-overlay:hover { .account__avatar-overlay:hover {
@ -84,7 +85,7 @@ input.button {
} }
.images .clickable { .images .clickable {
width: 20%; width: 5vw;
margin-right: 1em; margin-right: 1em;
cursor: pointer; cursor: pointer;
text-align: center; text-align: center;

View File

@ -0,0 +1,38 @@
const fs = require('fs');
const csv = require('csv-parser');
const csvFile = 'documents/mastodon_accounts_following.csv';
const jsonFile = 'documents/recommendations_abonnements_tk.json';
fs.createReadStream(csvFile)
.pipe(csv())
.on('data', (row) => {
const account = {
accountAddress: row['Account address'],
showBoosts: row['Show boosts'] === 'true',
notifyOnNewPosts: row['Notify on new posts'] === 'true',
languages: row.Languages.split(','),
};
console.log(account);
})
.on('end', () => {
console.log('Fin de la lecture du fichier CSV');
});
// Pour écrire le résultat en JSON
const jsonData = [];
fs.createReadStream(csvFile)
.pipe(csv())
.on('data', (row) => {
const account = {
accountAddress: row['Account address'],
showBoosts: row['Show boosts'] === 'true',
notifyOnNewPosts: row['Notify on new posts'] === 'true',
languages: row.Languages.split(','),
};
jsonData.push(account);
})
.on('end', () => {
fs.writeFileSync(jsonFile, JSON.stringify(jsonData, null, 2));
console.log('Fichier JSON généré');
});

90
wip/recommend_account.mjs Normal file
View File

@ -0,0 +1,90 @@
import fs from "fs";
import axios from "axios";
const nombre_comptes_recommandés = 3
/**
* recommander 3 comptes au hasard parmi les comptes listés dans document/recommendations_abonnements_tk.json
*/
async function recommendRandomAccount() {
// Charger le fichier JSON
const recommendations = JSON.parse(fs.readFileSync('documents/recommendations_abonnements_tk.json', 'utf8'));
// Sélectionner 3 comptes au hasard
const selectedAccounts = [];
for (let i = 0; i < nombre_comptes_recommandés; i++) {
const randomIndex = Math.floor(Math.random() * recommendations.length);
const account = recommendations[randomIndex];
selectedAccounts.push(account);
}
// Récupérer les informations des comptes sélectionnés
const accountsInfo = await Promise.all(selectedAccounts.map(async (account) => {
console.log('account', account)
const nickname = account.accountAddress;
const instance = nickname.split('@')[1];
const username = nickname.split('@')[0];
const url = `https://mastodon.cipherbliss.com/api/v2/search?q=${nickname}&resolve=true&limit=1`;
const token = process.env.USERTOKEN; // Remplacez par votre jeton d'accès
try {
const response = await axios.get(url, {
headers: {
Authorization: `Bearer ${token}`,
},
});
const accountInfo = response.data.accounts[0];
console.log('accountInfo', accountInfo)
return {
name: accountInfo.display_name,
nickname: accountInfo.acct,
description: accountInfo.note,
instance,
username,
};
} catch (error) {
console.log('error', error)
console.error(`Erreur lors de la récupération des informations du compte ${nickname}: ${error.message}`);
return null;
}
}));
// Fabriquer le message
let message = 'Suivez ces comptes Mastodon: \n\n';
accountsInfo.forEach((accountInfo, index) => {
if (accountInfo) {
const description = accountInfo.description;
let truncatedDescription = ''
if (description && description.length) {
truncatedDescription = description.substring(0, 147);
}
message += `* **${accountInfo.name}** (@${accountInfo.nickname}) : ${accountInfo.description}. https://${accountInfo.instance}/${accountInfo.username}\n`;
}
});
message += ' #followFriday #curation'
return sanitize(message);
}
async function main() {
let post = await recommendRandomAccount();
console.log('post', post);
}
function sanitize(text) {
const sanitizedText = text.replace(/<\/?[^>]+(>|$)/g, '');
const sanitizedTextWithoutEntities = sanitizedText.replace(/&#(\d+);/g, (match, code) => {
return String.fromCharCode(code);
});
return sanitizedTextWithoutEntities
}
main();