Skip to content

Instantly share code, notes, and snippets.

@Drakone
Last active January 7, 2018 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drakone/bc7396c5ebeb7cc53f7b913ba6396281 to your computer and use it in GitHub Desktop.
Save Drakone/bc7396c5ebeb7cc53f7b913ba6396281 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
</head>
<body>
<script>
var j = ""; // INSÉRER JSON
// DÉCOUPAGE ET TRI DES TAGS
function decoupageTag(listeTag) {
if (listeTag.length == 0){
return "";
}
if (listeTag.indexOf("|") == -1 && listeTag.length != 0) {
return listeTag;
}
if(listeTag.indexOf("|") >= 0) {
listeTag = listeTag.split("|");
listeTag = listeTag.sort();
return listeTag;
}
}
for (var i = 0; i < j.length; i++) {
j[i].influence_gastronomique = decoupageTag(j[i].influence_gastronomique);
j[i].categories_culinaires = decoupageTag(j[i].categories_culinaires);
j[i].resto_rapide = decoupageTag(j[i].resto_rapide);
j[i].ambiance = decoupageTag(j[i].ambiance);
// NETTOYAGE
j[i].adresse = j[i].adresse.split('&lt;br', 1)[0];
for (var nboucle = 1; nboucle < 20; nboucle++) {
j[i].description = j[i].description.replace(/&lt;\/?.{0,6}&gt;/,'');
j[i].description = j[i].description.replace(/&lt;.{0,6} .{0,20}.+&gt;/,'');
j[i].description = j[i].description.replace(/&lt;img .+&gt;/,'');
j[i].description = j[i].description.replace('&quot;','');
j[i].description = j[i].description.replace('\r\n','');
j[i].description = j[i].description.replace('&lt;p&gt;&amp;nbsp;&lt;', '');
j[i].description = j[i].description.replace('&amp;', '');
j[i].titre = j[i].titre.replace('&amp;', '');
j[i].titre = j[i].titre.replace('rsquo;', '\'');
j[i].titre = j[i].titre.replace('#8211;', '-');
j[i].titre = j[i].titre.replace('#038;', '&');
}
}
console.log(j);
// LISTES DE TAGS
var listeCategories = [];
var listeInfluences = [];
var listeResto = [];
var listeAmbiances = [];
var listeMontants = [];
// fonction
function compareEtAjoute(tagsPetitTableau, liste) {
for (var icat = 0; icat < tagsPetitTableau.length; icat++) {
if (tagsPetitTableau[icat].length == 1) { // UN SEUL ÉLÉMENTS
if (liste.indexOf(tagsPetitTableau) === -1) { // ÉLÉMENT DIFFÉRENT DE LA LISTE
liste.push(tagsPetitTableau);
}
}
if (tagsPetitTableau[icat].length != 1) { // PLUSIEURS ÉLÉMENTS
if (liste.indexOf(tagsPetitTableau[icat]) === -1) { // ÉLÉMENT DIFFÉRENT DE LA LISTE
liste.push(tagsPetitTableau[icat]);
}
}
}
}
// lancement
for (var i = 0; i < j.length; i++) {
compareEtAjoute(j[i].categories_culinaires, listeCategories);
compareEtAjoute(j[i].influence_gastronomique, listeInfluences);
compareEtAjoute(j[i].resto_rapide, listeResto);
compareEtAjoute(j[i].ambiance, listeAmbiances);
compareEtAjoute(j[i].montant_moyen, listeMontants);
}
// SELECTION DES CHAMPS
k = JSON.stringify(j, ['titre', 'description', 'image', 'adresse', 'code_postal', 'ville', 'pays', 'tel_fixe', 'mel_public', 'site_internet', 'facebook', 'nom_representant', 'fonction', 'montant_moyen', 'type_etablissement', 'categories_culinaires', 'resto_rapide', 'influence_gastronomique', 'ambiance'], '\t');
// AFFICHAGE
document.write("<code><pre>", k, "</code></pre>");
// fonction
function afficherListe(nomListe) {
document.write("<br /><h1>Liste de tags</h1><ul>")
for (var i = 0; i < nomListe.length; i++) {
document.write("<li>", nomListe[i], "</li>")
}
document.write("</ul>")
}
// lancement
afficherListe(listeCategories);
afficherListe(listeInfluences);
afficherListe(listeResto);
afficherListe(listeAmbiances);
afficherListe(listeMontants);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment