forked from Muirfield/pocketmine-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.php
51 lines (48 loc) · 1.52 KB
/
stats.php
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
<?php
//
// Get github download stats
//
function req($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch,CURLOPT_USERAGENT,"alejandroliu");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Get the response and close the channel.
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response);
}
//$data = file_get_contents();
//echo $data;
///$url = "https://api.github.com/users/alejandroliu/repos";
//print_r( req("https://api.github.com/users/alejandroliu/repos"));
//echo req("https://api.github.com/repos/alejandroliu/bad-plugins/releases");
//print_r( req("https://api.github.com/repos/alejandroliu/bad-plugins/releases"));
//print_r( req("https://api.github.com/repos/alejandroliu/pocketmine-plugins/releases"));
foreach (req("https://api.github.com/repos/alejandroliu/pocketmine-plugins/releases")
as $rel) {
if (isset($rel->name) && $rel->name)
echo "# ".$rel->name."\n";
elseif (isset($rel->tag_name) && $rel->tag_name)
echo "# ".$rel->tag_name."\n";
else
echo "# release\n";
$tab = [];
$cols = [1,1];
if (isset($rel->assets)) {
foreach ($rel->assets as $a) {
if (isset($a->name) && isset($a->download_count)) {
$tab[] = [ $a->name, $a->download_count ];
}
}
}
foreach ($tab as $row) {
for ($i=0;$i<count($cols);$i++) {
if (strlen($row[$i]) > $cols[$i]) $cols[$i] = strlen($row[$i]);
}
}
foreach ($tab as $row) {
printf(" - %-".$cols[0]."s %".$cols[1]."d\n",$row[0],$row[1]);
}
}