Skip to content

Instantly share code, notes, and snippets.

@maerlyn
Created December 26, 2012 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maerlyn/4380884 to your computer and use it in GitHub Desktop.
Save maerlyn/4380884 to your computer and use it in GitHub Desktop.
script to get sum-by-type reputation changes on SO
<?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";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment