-
Notifications
You must be signed in to change notification settings - Fork 0
/
summaryApi.js
61 lines (56 loc) · 2.22 KB
/
summaryApi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import fetch from "node-fetch";
// import SummarizerManager from "node-summarizer/src/SummarizerManager.js";
// import * as cheerio from "cheerio";
// // sk - tLNvV11GOiZw3OBh5CPiT3BlbkFJMfJRo9xXtpbB9N8Dx3cD;
// // sk - wWxugOwo9Ze5RPaaZpSTT3BlbkFJh3prjghtv0u1dDL4LIUn;
// async function summarizeArticle(articleUrl) {
// try {
// // Fetch article content (replace with your actual fetching mechanism)
// const response = await fetch(articleUrl);
// // console.log("response: ", response);
// const html = await response.text();
// // console.log("html: ", html);
// // Use cheerio to extract the article title and text
// const $ = cheerio.load(html);
// const title = $("head title").text();
// const paragraphs = $("p")
// .toArray()
// .map((p) => $(p).text())
// .join("\n");
// console.log("title: ", title);
// console.log("para: ", paragraphs);
// console.log("Original Article (excerpt):");
// console.log(articleText.substring(0, 100) + "rest of text..."); // Show first 100 characters (adjust as needed)
// console.log("\nSummary:");
// // console.log(summary);
// } catch (error) {
// console.error("Error fetching or summarizing article:", error);
// }
// }
// // Replace this with your HTML parsing logic to extract text content
// function extractTextFromHtml(htmlContent) {
// // Implement logic using a library like cheerio to remove HTML tags and extract text
// // This is a placeholder for demonstration purposes
// return htmlContent.replace(/<[^>]*>/g, " "); // Simple replacement (improve for real use)
// }
// // Example usage
// export default summarizeArticle;
const createSummary = async () => {
const url =
"https://contentai-net-text-generation.p.rapidapi.com/v1/text/blog-articles?category=health-and-medicine";
const options = {
method: "GET",
headers: {
"X-RapidAPI-Key": "11bc3f3af2msh96647404de321a5p1a8f34jsne18d0bbf38d3",
"X-RapidAPI-Host": "contentai-net-text-generation.p.rapidapi.com",
},
};
try {
const response = await fetch(url, options);
const result = await response.text();
// console.log(""result);
} catch (error) {
console.error(error);
}
};
export default createSummary;