Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $data = file_get_contents('http://wiki.scratch.mit.edu/w/api.php?action=query&titles=' . rawurlencode('Scratch Wiki:Elections/October 2014') . '&prop=revisions&rvprop=content&format=xml&salt=' . md5(time()));
- $xml = new SimpleXMLElement($data);
- $votes = (string) ($xml->query->pages->page->revisions->rev);
- $lines = explode("\n", $votes);
- $vote_lines = array();
- foreach ($lines as $val) {
- $val = trim($val);
- if (strpos($val, '|') === 0 && strlen($val) > 2) {
- $vote_lines[] = $val;
- }
- }
- $votes = array();
- foreach ($vote_lines as $val) {
- preg_match_all('%\| *([^ |]+)%s', $val, $columns);
- $voter = $columns[1][0];
- unset($columns[1][0]);
- $i = sizeof($columns[1]);
- foreach ($columns[1] as $vote) {
- if (!strstr($vote, 'N/A') && strpos($vote, '<') !== 0) {
- if (isset($votes[strtolower($vote)])) {
- $votes[strtolower($vote)] += $i;
- } else {
- $votes[strtolower($vote)] = $i;
- }
- $i--;
- }
- }
- }
- natsort($votes);
- $votes = array_reverse($votes);
- echo 'Scratch Wiki Vote Calculator - COPYRIGHT (C)2014 Jacob G.' . "\n";
- echo 'There are currently ' . sizeof($vote_lines) . ' votes, and your results are...' . "\n";
- $i = 0;
- foreach ($votes as $key => $val) {
- $i++;
- printf('%2d:%15s with %5d points', $i, $key, $val);
- echo "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement