-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
101 lines (89 loc) · 3.43 KB
/
main.js
File metadata and controls
101 lines (89 loc) · 3.43 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
const request = require('request');
const path = require('path');
const fs = require('fs');
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const createpdfDoc = require('./pdfkit');
const URL = 'https://github.com/topics';
const baseURL = 'https://github.com';
const rootPath = path.join(__dirname,'Open Source Projects');
createFolder(rootPath);
request(URL, function (error, response, html) {
if (error) {
console.error('error:', error);
} else {
// console.log(html);
const dom = new JSDOM(html);
const document = dom.window.document;
const topicsAnchorTags = document.querySelectorAll('.container-lg.p-responsive.mt-6 a');
for(let topicAnchor of topicsAnchorTags){
let topicURL = topicAnchor.href;
topicURL = baseURL + topicURL;
let topicName = topicURL.split('/').pop();
console.log(`Topic Name --> ${topicName} [Link --> ${topicURL}]`);
// request(topicURL,getRepositories);
getRepositories(topicURL,topicName)
}
}
});
function getRepositories(topicURL,topicName){
const fpath = path.join(rootPath,topicName);
createFolder(fpath);
request(topicURL,cb);
function cb(error,response,html){
if (error) {
console.error('error:', error);
} else {
// console.log(html);
const dom = new JSDOM(html);
const document = dom.window.document;
const repoAnchorTags = document.querySelectorAll('h3 a[data-ga-click="Explore, go to repository, location:explore feed"]');
for(let i = 0; i<8 ; i++){
let repoURL = repoAnchorTags[i].href;
repoURL = baseURL + repoURL;
let repoName = repoURL.split('/').pop();
// console.log(`Repo Name --> ${repoName} [Link --> ${repoURL}]`);
repoURL += '/issues';
getIssues(repoURL,repoName,fpath);
}
}
}
}
function getIssues(repoURL,repoName,fpath){
// console.log(repoURL);
request(repoURL,cb);
function cb(error,response,html){
if (error) {
console.error('error:', error);
} else {
// console.log(html);
const dom = new JSDOM(html);
const document = dom.window.document;
const issueAnchorTags = document.querySelectorAll('a[data-hovercard-type="issue"]');
console.log(issueAnchorTags.length);
let issuesArr = [];
for(let i = 0; i<issueAnchorTags.length; i++){
let issueName = issueAnchorTags[i].textContent;
let issueLink = issueAnchorTags[i].href;
issueLink = baseURL + issueLink;
// console.log(`Issue --> ${issueName} --> [${issueLink}]`);
const issueObj = {
issueName,issueLink
}
issuesArr.push(issueObj);
// createpdfDoc(issueName,issueLink,fpath,repoName);
}
// console.log(issuesArr);
// for creating json file
let issuesData = JSON.stringify(issuesArr);
const filePath = path.join(fpath,`${repoName}.json`)
fs.writeFileSync(filePath,issuesData);
// for creating pdf file
createpdfDoc(issuesArr,fpath,repoName);
}
}
}
function createFolder(fpath){
if(!fs.existsSync(fpath))
fs.mkdirSync(fpath);
}