-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_Scrapper.js
More file actions
133 lines (107 loc) · 3.19 KB
/
github_Scrapper.js
File metadata and controls
133 lines (107 loc) · 3.19 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const request = require("request");
const cheerio = require("cheerio");
let { jsPDF } = require("jspdf");
const fs = require("fs");
let $;
let data = {};
request("https://github.com/topics", function (err, res, body) {
$ = cheerio.load(body);
let topThreeTopics = $(
".no-underline.d-flex.flex-column.flex-justify-center"
);
for (let i = 0; i < 3; i++) {
topicLinkGenerator($(topThreeTopics[i]).attr("href"), getTopicPage);
}
});
function topicLinkGenerator(subLink, callback) {
callback("https://github.com" + subLink);
}
function getTopicPage(url) {
request(url, function (err, res, body) {
let urlArray = url.split("/");
let topicName = urlArray[urlArray.length - 1];
findProjects(topicName, body, findIssues);
});
}
function findProjects(folderName, body, callback) {
fs.mkdirSync(folderName);
if (!body) {
return;
} else {
$ = cheerio.load(body);
}
let allProjects = $(".d-flex.flex-justify-between.my-3 h1 ");
if (allProjects.length > 8) {
allProjects = allProjects.slice(0, 8);
}
for (let i = 0; i < allProjects.length; i++) {
callback(
"https://github.com" +
$($(allProjects[i]).find("a")[1]).attr("href") +
"/issues",
folderName,
issueProcessor,
$($(allProjects[i]).find("a")[1]).text()
);
}
}
function findIssues(url, folderName, callback, projectName) {
request(url, (err, res, body) => {
if (!body) {
return;
} else {
$ = cheerio.load(body);
}
let allIssues = $(
".Link--primary.v-align-middle.no-underline.h4.js-navigation-open"
);
if (allIssues.length <= 0) {
callback(folderName, null, null);
} else {
for (let i = 0; i < allIssues.length; i++) {
callback(
folderName,
$(allIssues[i]).text(),
"https://github.com" + $(allIssues[i]).attr("href"),
projectName
);
}
}
});
}
function issueProcessor(topic, issue, issueUrl, projectName) {
if (projectName) projectName = projectName.trim();
if (issue) {
let pdfPath = `./${topic}/${projectName}.pdf`;
if (!data[topic]) {
data[topic] = [
{ projectName: projectName, issues: [{ issue, url: issueUrl }] },
];
pdfGenerator(pdfPath, projectName, topic);
} else {
let requiredProjectIndex = data[topic].findIndex(
(p) => p.projectName === projectName
);
if (requiredProjectIndex !== -1) {
data[topic][requiredProjectIndex].issues.push({ issue, url: issueUrl });
pdfGenerator(pdfPath, projectName, topic);
} else {
data[topic].push({
projectName: projectName,
issues: [{ issue, url: issueUrl }],
});
pdfGenerator(pdfPath, projectName, topic);
}
}
}
}
function pdfGenerator(path, projectName, topic) {
let doc = new jsPDF();
let requiredIssues = data[topic].find(
(p) => p.projectName === projectName
).issues;
requiredIssues.forEach(function (issue, i) {
doc.text(5, 15 + i * 15, "issue: " + issue.issue + "\nURL: " + issue.url);
});
doc.save(path);
}