-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_users_contribs.php
executable file
·84 lines (65 loc) · 2.95 KB
/
get_users_contribs.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
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
<?php
// 2021_08_18 -
include_once "config.php";
include_once "script.funcs.php";
$ERRORUSER = "";
/* The following part: read the users.txt file and get the github-infos of each one,
* then save it to a json file
*/
$fpu = fopen("users.txt", "r");
while (($user = fgets($fpu)) !== false) { // WHILE read file
$user = str_replace("\n", "", $user);
$mktime = microtime();
$thisyear = date('Y-m-d\TH:i:s' . substr((string)$mktime, 1, 4) . '\Z');
$lastyear = date('Y-m-d\TH:i:s' . substr((string)$mktime, 1, 4) . '\Z', strtotime("-1 year"));
$yearbeforelast = date('Y-m-d\TH:i:s' . substr((string)$mktime, 1, 4) . '\Z', strtotime("-2 years"));
// -1 year to NOW
$rwr = runwhenready("graphql");
// echo "USER: {$user}, -1 year - ResourcesLimit: {$rwr}) ";
$thejson = get_json_post_token("/graphql", $user, $lastyear, $thisyear);
$djson = json_dec($thejson);
/* FIX? long line.. */
if (isset($djson["data"]["user"]["contributionsCollection"]["contributionCalendar"]["totalContributions"])) {
$usercontribsly = $djson["data"]["user"]["contributionsCollection"]["contributionCalendar"]["totalContributions"];
}
if ($djson == "JSONERROR") { $ERRORUSER .= "{$user}, "; }
// -2 year to -1 year
$rwr = runwhenready("graphql");
// echo ", -2 to -1 year - ResourcesLimit: {$rwr} \t";
$thejson = get_json_post_token("/graphql", $user, $yearbeforelast, $lastyear);
$djson = json_dec($thejson);
/* FIX? long line.. */
if (isset($djson["data"]["user"]["contributionsCollection"]["contributionCalendar"]["totalContributions"])) {
$usercontribsybl = $djson["data"]["user"]["contributionsCollection"]["contributionCalendar"]["totalContributions"];
}
if ($djson == "JSONERROR") { $ERRORUSER .= "{$user}, "; }
// SUM the 2 year contributions
if (!isset($usercontribsly)) { $usercontribsly = 0; }
if (!isset($usercontribsybl)) { $usercontribsybl = 0; }
$usercontribstotal = $usercontribsly + $usercontribsybl;
echo "User: {$user},\t Contribs: LY: {$usercontribsly}, YBL: {$usercontribsybl}, TOTAL: {$usercontribstotal} ResourcesLimit: {$rwr} \n";
$auc[] = array("usercontribs" => $usercontribstotal, "user" => $user);
} // END OF WHILE read file
fclose($fpu);
// let's short the users array so the most contributions goes up
$usercontribs = array_column($auc, 'usercontribs');
$user = array_column($auc, 'user');
array_multisort($usercontribs, SORT_DESC, $user, SORT_ASC, $auc);
$fp = fopen("sum_contr-3000.txt", 'w+');
for ($i = 0; $i < RESULTSNUMBER; $i++) {
if (isset($auc[$i])) {
fwrite($fp, "{$auc[$i]["usercontribs"]}, {$auc[$i]["user"]}");
}
if ($i < (RESULTSNUMBER - 1)) {
fwrite($fp, "\n");
}
}
fclose($fp);
echo "\n\n\n\n\n";
foreach ($auc as $line) {
echo "{$line["usercontribs"]}, {$line["user"]}\n";
}
echo "\nERRORS: {$ERRORS}\n";
echo "--------------------\nUSER ERRORS: {$ERRORUSER}\n";
echo "\n<br />Done users_contribs ..,\n";
?>