🎉 export script for framalibre works
This commit is contained in:
commit
e0880dd69d
|
@ -0,0 +1,2 @@
|
|||
node_modules
|
||||
.idea
|
|
@ -0,0 +1,19 @@
|
|||
# Data scraping de framalibre
|
||||
configurer main.js pour définir l'ID maximale
|
||||
# Utilisation
|
||||
Installer les paquets npm
|
||||
et lancer la commande
|
||||
node main.js
|
||||
_________________
|
||||
# documentation:
|
||||
## Pseudo API
|
||||
https://framalibre.org/content/pseudo-api
|
||||
|
||||
Vous pouvez accéder aux sortie JSON des catégories, termes, et contenus de l'annuaire Framalibre
|
||||
|
||||
Liste des vocabulaires de l'annuaire : https://framalibre.org/vocabularies/json (on repère par exemple le vocabulaire "annuaires")
|
||||
Liste des catégories du vocabulaire "annuaires" : https://framalibre.org/category/annuaires/json (on repère par exemple la catégorie "CMS", dont l'identifiant est "308")
|
||||
Termes d'une catégorie : https://framalibre.org/taxonomy/term/308/json permet de lister tous les CMS de Framalibre, dont "Jami", avec l'identifiant "1075"
|
||||
Sortie JSON d'un contenu : https://framalibre.org/content/1075/json pour afficher le JSON de la fiche "Jami", ou https://framalibre.org/content/284/json pour le livre "Guide d'autodéfense numérique". (bon, *tous* les champs sont volontairement affichés, c'est donc un peu sale car une fiche logicielle affiche par exemple "ISBN". Si les résultats sont vides, ils peuvent être masqués, mais ça permettait de montrer le schéma de données, lui même non définitif).
|
||||
|
||||
Il ne s'agit évidemment que d'une API d'affichage (elle ne permet pas de rentrer une info dans Framalibre, juste de les afficher dans un format lisible par une machine).
|
|
@ -0,0 +1,66 @@
|
|||
// parse framalibre catalog and merge json in output
|
||||
// API URL example 'https://framalibre.org/content/1075/json'
|
||||
|
||||
const fs = require('fs');
|
||||
const axios = require('axios');
|
||||
|
||||
const min_id = 0;
|
||||
// const max_id = 1417; // 1417 = fiche de "i hate money"
|
||||
const max_id = 1417; // 1417 = fiche de "i hate money"
|
||||
|
||||
const mergedCatalog = [];
|
||||
|
||||
class Methodos {
|
||||
fetchCatalog() {
|
||||
|
||||
const self = this;
|
||||
for (var ii = min_id; ii <= max_id; ii++) {
|
||||
console.log('ID', ii, ')')
|
||||
|
||||
console.log('call api with id ', ii)
|
||||
axios.get(`https://framalibre.org/content/${ii}/json`)
|
||||
.then((resp) => {
|
||||
for (let index in resp.data.nodes) {
|
||||
let toAdd = resp.data.nodes[index].node
|
||||
console.log('fiche', toAdd.Titre)
|
||||
this.addtocatalog(toAdd)
|
||||
}
|
||||
|
||||
})
|
||||
.then(resp => {
|
||||
this.writeOutPut(mergedCatalog);
|
||||
})
|
||||
.catch(err => console.error(err))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
writeOutPut(mergedCatalog) {
|
||||
console.log('mergedCatalog.length', mergedCatalog.length)
|
||||
|
||||
let m = mergedCatalog.map(elem => JSON.stringify(elem));
|
||||
let outJson = {}
|
||||
for (let index in mergedCatalog) {
|
||||
outJson[index * 1 + 1] = mergedCatalog[index];
|
||||
}
|
||||
let catalogPath = `./output/catalog_from_${min_id}_to_${max_id}.json`;
|
||||
let stringifiedCatalog = JSON.stringify(outJson)
|
||||
console.log('stringifiedCatalog', stringifiedCatalog)
|
||||
fs.writeFile(catalogPath, stringifiedCatalog, (err) => {
|
||||
if (err) throw err;
|
||||
console.log('catalog.js Replaced!');
|
||||
})
|
||||
return mergedCatalog;
|
||||
}
|
||||
|
||||
addtocatalog(index) {
|
||||
mergedCatalog.push(index)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let m = new Methodos();
|
||||
m.fetchCatalog();
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "scraping-framalibre",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"axios": {
|
||||
"version": "0.20.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.20.0.tgz",
|
||||
"integrity": "sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.10.0"
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.13.0",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz",
|
||||
"integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA=="
|
||||
},
|
||||
"node-fs": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/node-fs/-/node-fs-0.1.7.tgz",
|
||||
"integrity": "sha1-MjI8zLRsn78PwRgS1FAhzDHTJbs="
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "scraping-framalibre",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^0.20.0",
|
||||
"node-fs": "^0.1.7"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue