make recommendations of account, add more wiki fr osm

This commit is contained in:
Tykayn 2025-01-11 23:25:47 +01:00 committed by tykayn
parent e15bfb07a0
commit 400e1b2b42
6 changed files with 24105 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
jq -s '.[] |.query.search' recherche_pages_fr*.json > all_wiki_osm.json

File diff suppressed because one or more lines are too long

36
helpers/reco.mjs Normal file
View File

@ -0,0 +1,36 @@
import fs from "node:fs";
import axios from "axios";
// Charger le fichier JSON
const recommendations = JSON.parse(fs.readFileSync('documents/recommendations_abonnements.json', 'utf8'));
// Fonction pour récupérer les informations d'un compte Mastodon à partir de son ID
async function getAccountInfo(id) {
const response = await axios.get(`https://mastodon.cipherbliss.com/api/v1/accounts/${id}`);
const account = response.data;
return {
pseudo: account.username,
name: account.display_name,
description: account.note
};
}
// Sélectionner 3 comptes au hasard
const selectedAccounts = [];
for (let i = 0; i < 3; i++) {
const randomIndex = Math.floor(Math.random() * recommendations.length);
const accountId = recommendations[randomIndex].id;
selectedAccounts.push(accountId);
}
// Récupérer les informations des comptes sélectionnés
const accountsInfo = await Promise.all(selectedAccounts.map(async (id) => {
return getAccountInfo(id);
}));
// Générer le message de recommandation
const message = `Je vous recommande de suivre ces trois comptes Mastodon :
* ${accountsInfo[0].pseudo} (${accountsInfo[0].name}) - ${accountsInfo[0].description}
* ${accountsInfo[1].pseudo} (${accountsInfo[1].name}) - ${accountsInfo[1].description}
* ${accountsInfo[2].pseudo} (${accountsInfo[2].name}) - ${accountsInfo[2].description}`;
console.log(message);

50
helpers/wiki_fr.mjs Normal file
View File

@ -0,0 +1,50 @@
import fs from 'fs';
import path, {dirname} from 'path';
import axios from 'axios';
import {fileURLToPath} from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
// Charger le fichier JSON
const wikiArticles = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'assets', 'documents', 'all_wiki_osm.json'), 'utf8'));
// Sélectionner un article au hasard
const randomIndex = Math.floor(Math.random() * wikiArticles['elements'].length);
console.log('wikiArticles[\'elements\']', wikiArticles['elements'].length)
const selectedArticle = wikiArticles['elements'][randomIndex];
// Récupérer le titre et la description de l'article
const title = selectedArticle.title;
const pageId = selectedArticle.pageid;
// Récupérer le contenu de l'article via l'API de MediaWiki
const wikiApiUrl = `https://wiki.openstreetmap.org/w/api.php`;
const params = {
action: 'parse',
pageid: pageId,
format: 'json',
prop: 'text',
section: 0
};
axios.get(wikiApiUrl, {params})
.then(response => {
const articleContent = response.data.parse.text['*'];
const firstParagraph = articleContent.split('<p>')[1].split('</p>')[0];
// Sanitizer le texte
const sanitizedText = firstParagraph.replace(/<\/?[^>]+(>|$)/g, '');
const sanitizedTextWithoutEntities = sanitizedText.replace(/&#(\d+);/g, (match, code) => {
return String.fromCharCode(code);
});
// Générer le message
const message = `Je vous recommande de lire l'article "${title}" sur le wiki d'OpenStreetMap :
${sanitizedTextWithoutEntities}
Lire la suite sur : https://wiki.openstreetmap.org/wiki/${title}`;
console.log(message);
})
.catch(error => {
console.error(error);
});