public
Created

script to get sum-by-type reputation changes on SO

  • Download Gist
README.md
Markdown
seapi.php
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
<?php
 
$user_id = 308825;
$url_pattern = "https://api.stackexchange.com/2.1/users/%d/reputation-history?page=%s&pagesize=100&site=stackoverflow";
 
$page = 1;
$sum_by_type = array();
do {
echo "\rgetting page " . $page . "...";
 
$url = sprintf($url_pattern, $user_id, $page);
$contents = gzdecode(file_get_contents($url));
$page_contents = json_decode($contents, true);
 
foreach ($page_contents["items"] as $v) {
if (!isset($sum_by_type[$v["reputation_history_type"]])) {
$sum_by_type[$v["reputation_history_type"]] = 0;
}
 
$sum_by_type[$v["reputation_history_type"]] += $v["reputation_change"];
}
 
 
$has_more = $page_contents["has_more"];
++$page;
} while ($has_more);
 
echo "\n\n";
 
arsort($sum_by_type);
 
foreach ($sum_by_type as $k => $v) {
echo $k . "\t" . $v . "\n";
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.