forked from Upvision/upvision.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-data.mjs
93 lines (82 loc) · 2.39 KB
/
fetch-data.mjs
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
import fs from 'fs';
import axios from 'axios';
// ! Github Data
const ghKey = process.env.GHTOKEN
const query = `
query OrgDetails {
organization(login:"UpVision") {
repositories(first: 10, orderBy: {field: STARGAZERS, direction: DESC}) {
edges {
node {
name
description
url
stargazers {
totalCount
}
openGraphImageUrl
}
}
}
}
}
`
let request = (await axios({
url: 'https://api.github.com/graphql',
method: 'post',
headers: {
Authorization: `bearer ${ ghKey }`
},
data: {
query: query
}
})).data;
if (request.error) throw request.error;
let data = request.data;
await Promise.all(data.organization.repositories.edges.map(async (edge) => {
edge.node.contributors = []
let contributors = await axios({
url: `https://api.github.com/repos/UpVision/${edge.node.name}/contributors`,
method: 'get',
headers: {
"Authorization": `token ${ ghKey }`,
}
});
if (contributors.data){
contributors.data.forEach(contributor => {
edge.node.contributors.push({
'profileLink': contributor.url,
'imageURL': contributor.avatar_url,
'altTag': contributor.login
})
});
}
}));
let finalData = data.organization.repositories.edges.map(edge => {
return edge.node;
});
fs.writeFile('./data/githubData.json', JSON.stringify(finalData, null, 2), err => {
if (err) throw err;
console.log("Github Data written, succesfully!");
})
// ! Google calendar Data
const googleAuth = process.env.GCAUTH
const calendarId = "[email protected]"
let now = new Date();
let nowp3 = new Date(now);
nowp3.setMonth(nowp3.getMonth() + 3);
if (nowp3.getDate() != now.getDate()) nowp3.setDate(0);
await axios({
url: `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events`,
method: 'get',
params: {
key: `${ googleAuth }`,
timeMax: `${ nowp3.toISOString() }`,
timeMin: `${ now.toISOString() }`
}
}).then(res => {
fs.writeFile('./data/calendarData.json', JSON.stringify(res.data.items, null, 2), err => {
if (err) throw err;
console.log("Calendar Data written, succesfully!");
})
});