Skip to content

Instantly share code, notes, and snippets.

@bearlikelion
Last active December 20, 2015 15:59
Show Gist options
  • Save bearlikelion/6158225 to your computer and use it in GitHub Desktop.
Save bearlikelion/6158225 to your computer and use it in GitHub Desktop.
reddit.com/r/dota2 flair counter
<?php
$cache = memcache_connect('127.0.0.1', 11211);
$cached = memcache_get($cache, 'flair');
if ($cached == false) {
$account_info = self::reddit_info();
$login = self::reddit_api('login', $account_info);
$after = '';
$complete = 0;
while ($complete == 0) {
$selected_flair = json_decode(file_get_contents('http://api.reddit.com/r/dota2/api/flairlist?limit=1000' . $after ));
foreach ($selected_flair->users as $user_flair) $flair[] = $user_flair->flair_css_class;
if (isset($selected_flair->next)) $after = '&after=' . $selected_flair->next;
else {
$after = '';
$complete = 1;
}
}
memcache_set($cache, 'flair', $flair, 0, 900);
}
else $flair = memcache_get($cache, 'flair');
$users_with_flair = count($flair);
$subscribers = json_decode(file_get_contents('http://www.reddit.com/r/dota2/about.json'));
$subscribers = $subscribers->data->subscribers;
print $users_with_flair . ' out of ' . $subscribers . ' subscribers have selected flair (' . round($users_with_flair/$subscribers*100) . '%) <br /><br />';
$count = array_count_values(explode(',', join(',', $flair)));
arsort($count);
$table = 'Flair|Count<br />';
$table .= ':---|---:<br />';
if (isset($_GET['/flair?team']))
foreach ($count as $key => $value)
if (strpos($key, 'team') !== FALSE) $table .= $key . '|' . $value . '<br />';
else foreach ($count as $key => $value) $table .= $key . '|' . $value . '<br />';
print $table;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment