const { GoogleGenerativeAI } = require("@google/generative-ai"); const cheerio = require("cheerio"); const geminiDescriptionEdit = async (description, geminiApiKey, location) => { if (geminiApiKey != undefined) { const genAI = new GoogleGenerativeAI(geminiApiKey); const model = genAI.getGenerativeModel({ model: "gemini-pro" }); let prompt; if (location == "en") { prompt = description + " based on the text above, provide a detailed book description of similar length. Do not add any comments to the text, remain completely faithful to it. Only provide the book description, without using a title like book description."; console.log(prompt); } else { prompt = description + " yukarıdaki metine bağlı kalarak, benzer uzunlukta bir kitap tanımı ver. Metine hiçbir yorum katma, metine tamamen sadık kal. Sadece kitap tanımını ver, Kitap Tanımı şeklinde bir başlık kullanma"; } const result = await model.generateContent(prompt); const response = await result.response; return response.text(); } else { return description; } }; const extractBookId = (html) => { const $ = cheerio.load(html); let bookId = null; $("[data-csa-c-item-id]").each((index, element) => { const itemId = $(element).attr("data-csa-c-item-id"); if (!itemId.startsWith("amzn1.asin.1.B")) { bookId = itemId .replace(/^amzn1\.asin(\.amzn1)?\./, "") .replace(/^1\./, ""); return false; // Exit loop after finding the first valid bookId } }); return bookId; }; const extractBookPage = ($) => { const text = $("div.rpi-attribute-value span").text(); // İçeriği al const numberMatch = text.match(/\d+/); // Yalnızca rakamları al return numberMatch ? parseInt(numberMatch[0], 10) : null; // Sayıyı döndür }; const extractBookPublisher = ($) => { const publisherParentDiv = $(".rpi-icon.book_details-publisher").parent(); const publisherDiv = publisherParentDiv.next(); const spanInsidePublisherSibling = publisherDiv.find("span"); return spanInsidePublisherSibling.text(); }; const extractBookDate = ($) => { const dateParentDiv = $(".rpi-icon.book_details-publication_date").parent(); const dateDiv = dateParentDiv.next(); const spanInsideDateSibling = dateDiv.find("span"); return spanInsideDateSibling.text(); }; const extractBookDetails = async (html, isbn, geminiApiKey, location) => { const extractedText = html .match( /