-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
115 lines (105 loc) · 3.33 KB
/
utils.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
exports.googleapi = async (req) => {
var arr = [];
req.forEach(element => {
var temp = {};
temp.title = element.title;
temp.author = element.authors;
temp.book_image = element.thumbnail;
temp.language = element.language;
temp._id = element.id;
temp.type = "googleapi";
arr.push(temp);
});
return arr;
}
exports.dbooks = async (req) => {
var arr = [];
req.books.forEach(element => {
var temp = {};
temp.title = element.title;
temp.author = element.authors;
temp.book_image = element.image;
temp._id = element.id;
temp.type = "dbooks";
arr.push(temp);
});
return arr;
}
exports.amazon = async (req) => {
var temp = {};
temp.title = req.result[0].title;
temp.book_image = req.result[0].thumbnail;
temp._id = req.result[0].asin;
temp.type = "amazon";
return temp;
}
// function generateWordCombinations(queryArray) {
// const combinations = [];
// for (let i = 0; i < queryArray.length; i++) {
// for (let j = i + 1; j < queryArray.length; j++) {
// combinations.push(`${queryArray[i]} ${queryArray[j]}`);
// }
// }
// return combinations;
// }
// async function checkpdf(pdfUrls, queryArray) {
// const wordCombinations = generateWordCombinations(queryArray);
// let matchingPdfs = [];
// for (const pdfUrl of pdfUrls) {
// try {
// const response = await axios.get(pdfUrl, {
// responseType: 'arraybuffer'
// });
// const pdfData = response.data;
// const pdfText = await extractTextFromPdf(pdfData);
// // Check if any of the word combinations exist in the PDF text
// if (wordCombinations.some(combination => pdfText.includes(combination))) {
// matchingPdfs.push(pdfUrl);
// }
// } catch (error) {
// console.error(`Error processing PDF ${pdfUrl}:`, error);
// }
// }
// return matchingPdfs;
// }
// async function extractTextFromPdf(pdfData) {
// const dataBuffer = Buffer.from(pdfData);
// const options = {}; // You can pass options to pdf-parse if necessary
// const pdfText = await PDFParser(dataBuffer, options);
// return pdfText.text;
// }
// exports.googlesearch = async (req) => {
// var options = {
// host: "google.fr",
// qs: {
// q: req,
// filter: 0,
// pws: 0
// },
// num: 100
// };
// const links = await serp.search(options);
// var arr = [];
// links.forEach(element => {
// if (element.link.includes(".pdf")) {
// arr.push(element.link);
// }
// });
// pdf = checkpdf(arr, req);
// // return pdf;
// console.log(pdf);
// }
//extract pdf from google search and check whether pdf's first 5 pages make query or not
// var options = {
// host: "google.fr",
// qs: {
// q: "Rich Dad Poor Dad - What the Rich Teach Their Kids About Money filetype pdf doctype pdf",
// filter: 0,
// pws: 0
// },
// num: 100
// };
// (async () => {
// const links = await serp.search(options);
// console.log(links);
// })();