-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
91 lines (70 loc) · 2.95 KB
/
script.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
const request = require("request");
const cheerio = require("cheerio");
const fs = require("fs");
let $;
let data = {};
function linkGenerator(error, response, body){
if(!error && response.statusCode == 200){
// fs.writeFileSync("index.html", body);
$ = cheerio.load(body);
let alltopics = $(".no-underline.d-flex.flex-column.flex-justify-center");
let allTopicNames = $(".f3.lh-condensed.text-center.Link--primary.mb-0.mt-1");
console.log(typeof alltopics);
// console.log(alltopics);
console.log(alltopics.length);
for(let x = 0; x < alltopics.length; x++) {
getTopicPage($(allTopicNames[x]).text().trim(), "https://github.com/" + $(alltopics[x]).attr("href"));
// console.log($(allTopicNames[x]).text().trim());
// console.log("https://github.com/" + $(alltopics[x]).attr("href"));
}
}
// console.log(response);
}
function getTopicPage(name, url){
// url request => html page save
request(url, function (error, response, body){
if(!error && response.statusCode == 200){
// fs.writeFileSync(`${name}.html`, body);
$ = cheerio.load(body);
let allRepos = $(".f3.color-text-secondary.text-normal.lh-condensed .text-bold");
if(allRepos.length > 8){
allRepos = allRepos.slice(0,8);
}
for(let x = 0; x < allRepos.length; x++){
let repoTitle = $(allRepos[x]).text().trim();
let repoLink = "https://github.com/" + $(allRepos[x]).attr("href");
if(!data[name]){
data[name] = [{ "name": repoTitle, "link": repoLink}];
}else{
data[name].push({ name: repoTitle, link: repoLink});
}
// getIssuePage
getIssuesPage(name, repoTitle, repoLink + "/issues");
}
}
});
}
function getIssuesPage(topicName, repoName, url){
request(url, function(error, res, body){
let $ = cheerio.load(body);
let allIssues = $(".Link--primary.v-align-middle.no-underline.h4.js-navigation-open");
for(let x = 0; x < allIssues.length; x++){
let issueName = $(allIssues[x]).text().trim();
let issueLink = "https://github.com/" + $(allIssues[x]).attr("href");
let index = -1;
for(let i = 0; i < data[topicName].length; i++){
if(data[topicName][i].name === repoName){
index = i;
break;
}
}
if(data[topicName][index].issues === undefined){
data[topicName][index].issues = [{issueName, issueLink}];
}else{
data[topicName][index].issues.push({issueName, issueLink});
}
}
fs.writeFileSync("data.json", JSON.stringify(data));
});
}
request("https://github.com/topics", linkGenerator);