-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprogress.js
59 lines (55 loc) · 1.78 KB
/
progress.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
const fetch = require("node-fetch");
const fs = require("fs");
const DirectoriesID = {
"1.12": "37102",
"1.16": "14696",
"1.17": "33892",
"1.18": "57407",
"1.19": "68452"
};
let progress = {
"progress": "",
"1.12": "",
"1.16": "",
"1.17": "",
"1.18": "",
"1.19": "",
"data": {}
};
fetch("https://api.crowdin.com/api/v2/projects/442446/languages/progress",
{
method: "get",
headers: {
"Authorization": `Bearer ${process.env.CrowdinToken}`,
'Content-Type': 'application/json'
},
})
.then(res => res.json())
.then(json => {
progress.progress = ((json.data[0].data.words.translated / json.data[0].data.words.total) * 100).toFixed(3) + "%"
});
for (let version in DirectoriesID)
fetch(`https://api.crowdin.com/api/v2/projects/442446/directories/${DirectoriesID[version]}/languages/progress`,
{
method: "get",
headers: {
"Authorization": `Bearer ${process.env.CrowdinToken}`,
"Content-Type": "application/json",
},
})
.then(res => res.json())
.then(json => {
console.log(json);
let words = json.data[0].data.words
progress[version] = ((words.translated / words.total) * 100).toFixed(3) + "%";
progress.data[version] = {
translated: words.translated,
total: words.total
}
let t = true;
for (let i of Object.keys(progress)) if (i != "data" && progress[i].length == 0) t = false;
if (t) {
fs.existsSync("./data") || fs.mkdirSync("./data");
fs.writeFileSync("./data/progress.json", JSON.stringify(progress, null, 4));
}
});