FAQ
edit- What happened in 2017
- PHP has it's own function to make CSV, fputcsv()!
- Yes it does.
CSV Output
edityear,day1,day2,day3,day4,day5,day6,day7,day8,day9,day10,day11,day12,day13,day14
2009,278,139,100,63,49,49,34,64,61,38,38,32,95,107
2010,228,96,83,120,75,90,62,52,76,120,,,,
2011,195,98,88,66,48,34,27,30,34,42,42,27,37,53
2012,294,115,68,62,40,41,48,38,35,32,27,38,37,104
2013,336,116,62,44,35,43,47,46,35,31,24,31,51,138
2014,158,79,43,40,29,19,24,33,29,14,26,38,43,68
2015,561,764,431,162,125,87,97,111,107,92,66,61,75,107
2016,306,818,204,86,81,55,65,79,61,43,50,38,64,78
2017,222,84,58,30,37,45,433,567,143,121,74,85,71,138
2018,1145,249,99,79,79,68,79,49,52,50,43,46,68,103
2019,929,191,99,69,58,53,57,39,31,22,33,36,60,106
2020,940,182,109,68,64,91,78,56,47,44,26,38,65,79
Actual PHP Source
edit<?php
$numdays = 15;
@$thisyear = $argv[2];
@$cachefile = $argv[1];
echo "Using cache file: $cachefile\n";
echo "Running for ACE$thisyear\n";
$years = array();
$years[2009] = array();
$years[2009]['poll'] = 80;
$years[2009]['type'] = 2;
$years[2010] = array();
$years[2010]['poll'] = 130;
$years[2010]['type'] = 2;
$years[2011] = array();
$years[2011]['poll'] = 240;
$years[2011]['type'] = 2;
$years[2012] = array();
$years[2012]['poll'] = 259;
$years[2012]['type'] = 2;
$years[2013] = array();
$years[2013]['poll'] = 360;
$years[2013]['type'] = 2;
$years[2014] = array();
$years[2014]['poll'] = 392;
$years[2014]['type'] = 1;
$years[2015] = array();
$years[2015]['poll'] = 560;
$years[2015]['type'] = 1;
$years[2016] = array();
$years[2016]['poll'] = 612;
$years[2016]['type'] = 1;
$years[2017] = array();
$years[2017]['poll'] = 673;
$years[2017]['type'] = 1;
$years[2018] = array();
$years[2018]['poll'] = 710;
$years[2018]['type'] = 1;
$years[2019] = array();
$years[2019]['poll'] = 759;
$years[2019]['type'] = 1;
$years[2020] = array();
$years[2020]['poll'] = 808;
$years[2020]['type'] = 1;
if( !isset( $argv[2] ) || !isset( $argv[1] ) ) {
$triggerhelp = true;
echo "No cachefile or year specified\n\n";
} else {
$triggerhelp = false;
}
if( @$argv[1] == "--help" || @$argv[1] == "-h" || $triggerhelp === true ) {
$filename = $argv[0];
echo "\nACEByDay by SQL
Usage: $filename cachefilename.csv thisyear [-r | --refresh]
-r | --refresh = Refresh Cache
-h | --help = This text
thisyear = The current ACE year\n\n";
die();
}
if( @$argv[3] == "--refresh" || @$argv[3] == "-r" ) {
$refresh = true;
$out = "year,day1,day2,day3,day4,day5,day6,day7,day8,day9,day10,day11,day12,day13,day14\n";
} else {
$refresh = false;
$out = @file_get_contents( $cachefile );
if( $out === false ) {
die( "\nCouldn't find file: \"$cachefile\"\n" );
}
}
echo "Configuration:\n\n";
print_r( $years );
echo "\n";
$c = 0;
$days = array();
if( file_exists( $cachefile ) === true ) {
$out = file_get_contents( $cachefile );
echo "Cache found!\n";
$skipyear = true;
} else {
$skipyear = false;
$out = "year,day1,day2,day3,day4,day5,day6,day7,day8,day9,day10,day11,day12,day13,day14\n";
}
foreach( $years as $year=>$data ) {
echo "$year\n";
if( $year == $thisyear ) {
file_put_contents( $cachefile, $out );
$skipyear = false;
}
if( $refresh === true ) {
$skipyear = false;
}
if( $skipyear === false ) {
$poll = $data['poll'];
$toget = 5000;
if( $data['type'] == 1 ) {
$baseurl = "https://vote.wikimedia.org/w/index.php?limit=$toget&title=Special%3ASecurePoll%2Flist%2F$poll";
} else {
$baseurl = "https://en.wikipedia.org/w/index.php?limit=$toget&title=Special%3ASecurePoll%2Flist%2F$poll";
}
$page = file_get_contents( $baseurl );
preg_match_all( '/<td class="TablePager_col_vote_timestamp">(.*?)<\/td>/i', $page, $matches );
$votes = $matches[1];
$count = array();
foreach( $votes as $vote ) {
preg_match( '/\d\d:\d\d, (.*?) 20\d\d/i', $vote, $m );
$skip = false;
if( $m[1] == "24 November" && $year == 2017 ) {
$skip = true;
}
if( !$skip ) {
if( !isset( $count[$m[1]] ) ) {
$count[$m[1]] = 1;
if( !isset( $days[$year] ) ) {
$days[$year] = 1;
} else {
$days[$year]++;
}
} else {
$count[$m[1]]++;
}
}
}
print_r( $count );
$out .= "$year,";
if( count( $count ) < 14 ) {
$diff = 14 - count( $count );
while( $diff > 0 ) {
$count[] = "";
$diff--;
}
}
$cc_count = 0;
foreach( $count as $cc ) {
$out .= "$cc";
if( $cc_count < 13 ) {
$out .= ",";
}
$cc_count++;
}
$out .= "\n";
}
}
echo "Voting Days\n";
print_r( $days );
echo $out;
?>