aboutsummaryrefslogtreecommitdiff
path: root/scripts/download_count.js
blob: 47dae4bbdeebc311e93dd4a7e2062ab606384720 (plain)
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
const https = require("https");

let link = "/repos/0neGal/viper/releases";

let releases = {};
let total_count = 0;

let parse_release = (release) => {
	let assets = release.assets;
	let name = release.name + ":";

	for (let i = 0; i < assets.length; i++) {
		// dont count blockmaps
		if (assets[i].name.match("blockmap")) {
			continue;
		}

		switch(assets[i].name) {
			// dont count these files
			case "latest.yml":
			case "latest-linux.yml":
				continue;

			default:
				let downloads = assets[i].download_count;

				if (! releases[name]) {
					releases[name] = 0;
				}

				total_count += downloads;
				releases[name] += downloads;
		}

		if (i == assets.length - 1) {
			console.log(name, releases[name]);
		}
	}
}

let parse_json = (json) => {
	json = JSON.parse(json);
	for (let i = 0; i < json.length; i++) {
		parse_release(json[i]);
	}

	console.log();
	console.log("Total download count:", total_count);
}

https.get({
	host: "api.github.com",
	port: 443,
	path: link,
	method: "GET",
	headers: { "User-Agent": "viper" }
}, (res) => {
	res.setEncoding("utf8");
	let res_data = "";

	res.on("data", data => {
		res_data += data;
	});

	res.on("end", () => {
		parse_json(res_data);
	});
})