-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue.js
47 lines (46 loc) · 1.58 KB
/
issue.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
const request = require("request");
const cheerio = require("cheerio");
const fs = require("fs");
const pdfkit = require("pdfkit")
const path = require("path");
function getIssuesPageHtml(url, topic, repoName) {
request(url, cb);
function cb(err, response, html) {
if (err) {
console.log(err);
} else if(response.statusCode == 404) {
console.log("Page not Found");
} else {
// getRepoLink(html)
// console.log(html);
getIssues(html);
}
function getIssues(html){
let $ = cheerio.load(html);
let issuesEleArr =$(".Link--primary.v-align-middle.no-underline.h4.js-navigation-open.markdown-title");
let arr = [];
for(let i = 0; i < issuesEleArr.length; i++){
let link = $(issuesEleArr[i]).attr("href");
// console.log(link)
arr.push(link);
}
// console.log(topic, " ", arr);
let folderPath = path.join(__dirname, topic);
dirCreator(folderPath);
let filePath = path.join(folderPath, repoName + ".pdf")
console.log(filePath);
let text = JSON.stringify(arr)
let pdfDoc = new pdfkit();
pdfDoc.pipe(fs.createWriteStream(filePath));
pdfDoc.text(text);
pdfDoc.end();
// fs.writeFileSync(filePath, );
}
}
}
module.exports = getIssuesPageHtml;
function dirCreator(folderPath) {
if(fs.existsSync(folderPath) == false) {
fs.mkdirSync(folderPath);
}
}