plugin Marmiton
Page 1 sur 1
plugin Marmiton
plugin marmiton bientot seras finis, avec préparation: temps de cuisson et les étapes
fred je ne vole jamais ou je ne porte jamais des plugin obsolote de sarah ou jarvis ou meme ceux d'AVATAR, je développe mes propres plugin avec du javascript moderne, simple et facile a comprendre le code
celui de laurent ne fonctionne pas la preuve:
$('h4.recipe-card__title').each((index, element) => {
recipeTitles.push($(element).text());
});
var listRecetteUrl = [];
$('.MRTN__sc-1gofnyi-0').find('a').each(function (index, element) {
listRecetteUrl.push($(element).attr('href'));
});
fred, un apercus du code js du plugin marmiton en bas
exports.action = function(data, callback){
let client = setClient(data);
info("Marmiton from:", data.client, "To:", client);
marmiton (data, client);
callback();
}
async function marmiton(data, client) {
let sentence = /une recette(?: sur marmiton)? (.+)/i;
let regExp = sentence;
let nameRecipeMatch = data.action.rawSentence.toLowerCase().match(regExp);
let extractNameRecipe = nameRecipeMatch ? nameRecipeMatch[1].trim() : null;
if (!extractNameRecipe) {
Avatar.speak("Je ne peux pas donner une recette sans le nom de la recette", data.client, () => {
Avatar.Speech.end(data.client);
});
return;
}
let baseURL = `https://www.marmiton.org/recettes/recherche.aspx?aqt=${encodeURIComponent(extractNameRecipe)}`;
try {
const response = await fetch(baseURL);
if (response.status !== 200) {
throw new Error(`Code erreur: ${response.status}`);
}
const html = await response.text();
const cheerio = require('cheerio');
const $ = cheerio.load(html);
const nmbrRecette = Config.modules.Marmiton.nmbrRecette;
const recipeTitles = [];
$('h4.recipe-card__title').each((index, element) => {
recipeTitles.push($(element).text());
});
if (recipeTitles.length === 0) {
Avatar.speak("Aucune recette trouvée sur Marmiton.", data.client, () => {
Avatar.Speech.end(data.client);
});
return;
}
const message = recipeTitles.slice(0, nmbrRecette).join(', ');
Avatar.speak(`J'ai trouvé ${recipeTitles.length} recettes pour ${extractNameRecipe}. Voici pour les ${nmbrRecette} premiere recettes: ${message}.`, data.client, () => {
Avatar.Speech.end(data.client);
choixRecettes (extractNameRecipe, data, client)
});
} catch (error) {
Avatar.speak(`Erreur lors de la récupération des infos sur le site Marmiton. ${error.message}`, data.client, () => {
Avatar.Speech.end(data.client);
});
}
}
async function choixRecettes (extractNameRecipe, data, client) {
Avatar.askme('tu veux quelle recette ?', data.client, {
"*": "generic",
"terminer": "done"
}, 0, (answer, end) => {
if (!answer) {
Avatar.speak("Veuillez réessayer.", data.client, () => {
end(client);
return choixRecette (extractNameRecipe, data, client)
});
}
if (answer === "done") {
Avatar.speak("Terminé, A bientôt sur les recettes Marmiton", data.client, () => {
end(data.client, true);
});
return;
}
if (answer.indexOf('generic') != -1) {
end(client);
answer = answer.split(':')[1].toLowerCase();
if (answer.indexOf(answer) > -1) {
answer = extractNameRecipe;
return recetteIngrédientsPreparation(extractNameRecipe, data, client);
}
}
})
}
async function recetteIngrédientsPreparation(extractNameRecipe, data, client) {
Avatar.askme('tu veux les ingrédients ou la préparation ?', data.client, {
"*": "generic",
"terminer": "done"
}, 0, (answer, end) => {
if (!answer) {
Avatar.speak("Veuillez réessayer.", data.client, () => {
end(client);
return recetteIngrédientsPreparation (extractNameRecipe, data, client)
});
}
if (answer === "done") {
Avatar.speak("Terminé, A bientôt sur les recettes Marmiton", data.client, () => {
end(data.client, true);
});
return;
}
if (answer.indexOf('generic') != -1) {
end(client);
answer = answer.split(':')[1].toLowerCase();
if (answer.indexOf('les ingrédients ') > -1) {
return listRecetteIngredients (extractNameRecipe, data, client);
}
if (answer.indexOf('la préparation ') > -1) {
return listRecettePreparation (extractNameRecipe, data, client);
}
}
});
}
/*
async function listRecettePreparation (data, client) {
}
async function listRecetteIngredients (data, client) {
}
*/
function setClient (data) {
let client = data.client;
if (data.action.room) {
client = (data.action.room != 'current') ? data.action.room : (Avatar.currentRoom) ? Avatar.currentRoom : Config.default.client;
}
if (data.action.setRoom) {
client = data.action.setRoom;
}
return client;
}
fred je ne vole jamais ou je ne porte jamais des plugin obsolote de sarah ou jarvis ou meme ceux d'AVATAR, je développe mes propres plugin avec du javascript moderne, simple et facile a comprendre le code
celui de laurent ne fonctionne pas la preuve:
$('h4.recipe-card__title').each((index, element) => {
recipeTitles.push($(element).text());
});
var listRecetteUrl = [];
$('.MRTN__sc-1gofnyi-0').find('a').each(function (index, element) {
listRecetteUrl.push($(element).attr('href'));
});
fred, un apercus du code js du plugin marmiton en bas
exports.action = function(data, callback){
let client = setClient(data);
info("Marmiton from:", data.client, "To:", client);
marmiton (data, client);
callback();
}
async function marmiton(data, client) {
let sentence = /une recette(?: sur marmiton)? (.+)/i;
let regExp = sentence;
let nameRecipeMatch = data.action.rawSentence.toLowerCase().match(regExp);
let extractNameRecipe = nameRecipeMatch ? nameRecipeMatch[1].trim() : null;
if (!extractNameRecipe) {
Avatar.speak("Je ne peux pas donner une recette sans le nom de la recette", data.client, () => {
Avatar.Speech.end(data.client);
});
return;
}
let baseURL = `https://www.marmiton.org/recettes/recherche.aspx?aqt=${encodeURIComponent(extractNameRecipe)}`;
try {
const response = await fetch(baseURL);
if (response.status !== 200) {
throw new Error(`Code erreur: ${response.status}`);
}
const html = await response.text();
const cheerio = require('cheerio');
const $ = cheerio.load(html);
const nmbrRecette = Config.modules.Marmiton.nmbrRecette;
const recipeTitles = [];
$('h4.recipe-card__title').each((index, element) => {
recipeTitles.push($(element).text());
});
if (recipeTitles.length === 0) {
Avatar.speak("Aucune recette trouvée sur Marmiton.", data.client, () => {
Avatar.Speech.end(data.client);
});
return;
}
const message = recipeTitles.slice(0, nmbrRecette).join(', ');
Avatar.speak(`J'ai trouvé ${recipeTitles.length} recettes pour ${extractNameRecipe}. Voici pour les ${nmbrRecette} premiere recettes: ${message}.`, data.client, () => {
Avatar.Speech.end(data.client);
choixRecettes (extractNameRecipe, data, client)
});
} catch (error) {
Avatar.speak(`Erreur lors de la récupération des infos sur le site Marmiton. ${error.message}`, data.client, () => {
Avatar.Speech.end(data.client);
});
}
}
async function choixRecettes (extractNameRecipe, data, client) {
Avatar.askme('tu veux quelle recette ?', data.client, {
"*": "generic",
"terminer": "done"
}, 0, (answer, end) => {
if (!answer) {
Avatar.speak("Veuillez réessayer.", data.client, () => {
end(client);
return choixRecette (extractNameRecipe, data, client)
});
}
if (answer === "done") {
Avatar.speak("Terminé, A bientôt sur les recettes Marmiton", data.client, () => {
end(data.client, true);
});
return;
}
if (answer.indexOf('generic') != -1) {
end(client);
answer = answer.split(':')[1].toLowerCase();
if (answer.indexOf(answer) > -1) {
answer = extractNameRecipe;
return recetteIngrédientsPreparation(extractNameRecipe, data, client);
}
}
})
}
async function recetteIngrédientsPreparation(extractNameRecipe, data, client) {
Avatar.askme('tu veux les ingrédients ou la préparation ?', data.client, {
"*": "generic",
"terminer": "done"
}, 0, (answer, end) => {
if (!answer) {
Avatar.speak("Veuillez réessayer.", data.client, () => {
end(client);
return recetteIngrédientsPreparation (extractNameRecipe, data, client)
});
}
if (answer === "done") {
Avatar.speak("Terminé, A bientôt sur les recettes Marmiton", data.client, () => {
end(data.client, true);
});
return;
}
if (answer.indexOf('generic') != -1) {
end(client);
answer = answer.split(':')[1].toLowerCase();
if (answer.indexOf('les ingrédients ') > -1) {
return listRecetteIngredients (extractNameRecipe, data, client);
}
if (answer.indexOf('la préparation ') > -1) {
return listRecettePreparation (extractNameRecipe, data, client);
}
}
});
}
/*
async function listRecettePreparation (data, client) {
}
async function listRecetteIngredients (data, client) {
}
*/
function setClient (data) {
let client = data.client;
if (data.action.room) {
client = (data.action.room != 'current') ? data.action.room : (Avatar.currentRoom) ? Avatar.currentRoom : Config.default.client;
}
if (data.action.setRoom) {
client = data.action.setRoom;
}
return client;
}
halim- Messages : 89
Date d'inscription : 19/11/2022
Page 1 sur 1
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum
|
|