#!/usr/bin/perl # # Check Perl version # require 5.003; #require 'MyMail.pm'; require "ctime.pl" ; use Time::Local ; use CGI qw/:standard escapeHTML/; use LWP::Simple; $start_time = 966355200 ; # noon EST on 8/15 $end_time = $start_time + (16*24 + 7)*60*60 ; # 7pm EST on 8/31, midnight GMT $end_time += 8*24*60*60 ; # deadline extended by 8 days! $relative_url = url(-relative=>1); $webmaster = 'webmaster@icannnot.org' ; # Send error messages to browser: use CGI::Carp qw(fatalsToBrowser set_message); BEGIN { sub handle_errors { my $msg = shift ; $webmaster = 'webmaster@icannnot.org' ; print "

Oh No!!!!!

"; print "Got an unexpected error: $msg

"; print "Please inform $webmaster of this error." ; } set_message(\&handle_errors); } $logdir = "../endorsehistory"; #$logdir = "../../endorsehistory/test"; $vlogfile = "$logdir/verified.log"; $vfile = "verified.txt"; #%region_list = ( # 'AF'=>'Africa', # 'AP'=>'Asia/Australia/Pacific', # 'EU'=>'Europe', # 'LA'=>'Latin America/Caribbean', # 'NA'=>'North America', #) ; %lang_list = ('e' => "In English", 'd' => "Auf Deutsch", ); %month_list = ('Jan'=>0,'Feb'=>1,'Mar'=>2,'Apr'=>3,'May'=>4,'Jun'=>5,'Jul'=>6,'Aug'=>7,'Sep'=>8,'Oct'=>9,'Nov'=>10,'Dec'=>11); ########## English words ############################################### sub lang_e { $title = 'ICANNnot | ICANN Member Nomination Status' ; $region_list = { 'AF'=> 'Africa', 'AP'=> 'Asia/Australia/Pacific', 'EU'=> 'Europe', 'LA'=> 'Latin America/Caribbean', 'NA'=> 'North America', } ; %sort_by_list = ( 'e'=> "Sort by endorsements", 'n'=> "Sort by name", 'o'=> "Sort by order of submission"); %sorted_by_list = ( 'e'=> "Candidates sorted by endorsements", 'n'=> "Candidates sorted by name", 'o'=> "Candidates sorted by order of submission"); $heading = 'ICANN Member Nomination Status'; $translate_request = '

German translation by Alexander Svensson of ICANN Channel. Danke!
If you can translate this page into another language, please send an email
to ' . $webmaster . ' and I will add the translation to this page.
'; $t_Based_on_last_ICANN_update_at = 'ICANN's endorsement figures were last updated on" ; $t_Final_day = 'Final results!' ; $t_Change_region = 'Change region' ; $t_Region = 'Region' ; $t_Registered = 'Registered' ; $t_Verified = 'Activated' ; $t_Members_on_15_Aug = 'Members on 15 Aug.' ; $t_Current_approx = 'Current (est.)' ; $t_Projected = 'Projected' ; $t_Total_votes = 'Total votes' ; $t_Voter_Turnout_p = 'Voter Turnout %' ; $t_Projected_Turnout_p = 'Projected Turnout %'; $voter_information = ' Important voter information:

'; $t_Time_left = "Time left to make or change endorsements" ; $t_Candidate = 'Candidate' ; $t_Endorsements = ' Votes ' ; $t_Two_or_more_countries = 'Two or more
countries'; $t_Percentage = 'Percentage' ; $t_Percentage_of_total_endorsements = 'Percentage
of total
endorsements' ; $t_Percentage_of_verified_members = 'Percentage
of activated
members' ; $t_Projections_based_on_voter_turnout = "Projections based on
voter turnout" ; $t_If_elections_ended_now = "If elections
ended now?" ; $t_Guaranteed = "Guaranteed?" ; $t_at_least = "min." ; $t_Yes = 'Yes' ; $t_No = 'No' ; $t_Maximum_of = 'Maximum of' ; $t_member_nominated_candidates_except_for_ties_in = 'member-nominated candidates (except for ties) in '; $table_legend = ' '; $t_This_page_was_automatically_generated_on = 'This page was automatically generated on' ; } ########## Deutsch words ############################################### sub lang_d { $title = 'ICANNnot | Status der ICANN Mitglieder-Nominierung' ; $region_list = { 'AF'=> 'Afrika', 'AP'=> 'Asien/Australien/Pazifik', 'EU'=> 'Europa', 'LA'=> 'Lateinamerika/Karibik', 'NA'=> 'Nordamerika', } ; %sort_by_list = ( 'e' => "Nach Zahl der Unterstützer sortieren", 'n' => "Nach Namen sortieren", 'o' => "Nach Reihenfolge der Anmeldung sortieren"); %sorted_by_list = ('e' => "Kandidaten nach Zahl der Unterstützer", 'n' => "Kandidaten nach Namen", 'o' => "Kandidaten nach Reihenfolge der Anmeldung"); $heading = 'Status der ICANN Mitglieder-Nominierung'; $translate_request = '

Seite übersetzt von Alexander Svensson von ICANN Channel. Danke!
If you can translate this page into another language, please send an email
to ' . $webmaster . ' and I will add the translation to this page.
'; $t_Based_on_last_ICANN_update_at = 'ICANNs Unterstützerzahlen wurden zuletzt aktualisiert am' ; $t_Final_day = 'Final results!' ; $t_Change_region = 'Region wechseln' ; $t_Region = 'Region' ; $t_Registered = 'Angemeldet' ; #$t_Verified = 'Verifiziert' ; $t_Verified = 'Aktiviert' ; $t_Members_on_15_Aug = 'Mitglieder am 15.8.' ; $t_Current_approx = 'Derzeit (ca.)' ; $t_Projected = 'Hochgerechnet' ; $t_Total_votes = 'Stimmen igs.' ; $t_Voter_Turnout_p = 'Beteiligung %' ; $t_Projected_Turnout_p = 'Hochgerechnete Beteiligung %'; $voter_information = ' Wichtige Wählerinformationen:

'; $t_Time_left = "Zeit restlich" ; $t_Candidate = 'Kandidat/in' ; # $t_Endorsements = 'Unterstützer' ; $t_Endorsements = 'Stimmen' ; $t_Two_or_more_countries = '2 oder mehr
Länder'; $t_Percentage = 'Prozent' ; $t_Percentage_of_total_endorsements = 'Stimmenanteil' ; #$t_Percentage_of_verified_members = 'Stimmenanteil
verifiziert
Mitglieder' ; $t_Percentage_of_verified_members = 'Stimmenanteil
aktiviert
Mitglieder' ; $t_Projections_based_on_voter_turnout = 'Hochrechnungen auf der
Basis der Wahlbeteiligung' ; $t_If_elections_ended_now = 'Wäre jetzt
Wahlende?' ; $t_Guaranteed = 'Garantiert?' ; $t_at_least = 'mind.' ; $t_Yes = 'Ja' ; $t_No = 'Nein' ; $t_Maximum_of = 'Maximum von' ; $t_member_nominated_candidates_except_for_ties_in = 'Mitglieder-nominierten Kandidaten (außer bei Gleichstand) in '; $table_legend = ' '; $t_This_page_was_automatically_generated_on = 'Diese Seite wurde automatisch erstellt am' ; } ########## End of Deutsch words ############################################### # for http://members.icann.org/pubstats.html %region_list_rev = ('North America' => 'NA' , 'Africa' =>'AF', 'Asia and Pacific' => 'AP', 'Europe' => 'EU' , 'Latin America and the Caribbean' => 'LA') ; %region_regs = ('NA'=> 21596, 'AF'=> 787, 'AP'=> 93782, 'EU'=> 35942, 'LA'=> 6486) ; %region_verified0 = ( 'AF'=> 160, 'AP'=> 17977, 'EU'=> 12953, 'LA'=> 1706, 'NA'=> 7407, 'Time' => 966355200 + 9 * 60 * 60 + 8*60 # 9PM EST on 8/15 ; ) ; %region_verified_final = ( 'AF'=> 321, 'AP'=> 38397, 'EU'=> 23519, 'LA'=> 3571, 'NA'=> 10694, 'Time' => 966355200 + 9 * 60 * 60 + 8*60 # 9PM EST on 8/15 ; ) ; %region_limit =('NA'=> 3, 'AF'=> 5, 'AP'=> 3, 'EU'=> 2, 'LA'=> 4) ; $region = uc param('r'); if (!defined($region_regs{$region})) { $region = 'NA' ; } $africa = ($region eq 'AF'); $lang = lc param('l'); if (!defined($lang_list{$lang})) { $lang = 'e' ; } if ($lang eq 'e') { lang_e(); } elsif ($lang eq 'd') { lang_d(); } $sort_by = lc param('s'); if (!defined($sort_by_list{$sort_by})) { $sort_by = 'e' ; } $update_ps = param('ps'); $write_log = param('w'); if ($update_ps) { update_pubstats(); } else { main(); } exit 0; sub param_pop { my($x) = @_ ; param($x,$POP{$x}) ; } sub param_array { my @myparam =(); my $i = 0 ; foreach my $p (param) { $myparam[$i][0] = $p ; $myparam[$i][1] = param($p) ; $i++ ; } @myparam ; } sub region2page { my ($r) = @_ ; "http://members.icann.org/nom/cp/$r.html" ; } sub get_icann_page { my ($r) = @_ ; #get(region2page($r)); my $fn = "$logdir/$r"."final.log" ; `cat $fn` ; } sub get_verified { open (VER,"<$vfile"); my $region ; my $count ; while () { ($region,$count) = split ; $region_verified{$region} = $count ; } close VER ; } sub update_pubstats { my $page = get("http://members.icann.org/pubstats.html"); my @lines = split (/\n/,$page) ; my $table_header_found = 0 ; my $count ; my $region_name ; my $change = 0 ; my $uptime = time ; get_verified() ; for (my $i = 0 ; $i < @lines ; $i++) { if ($lines[$i] =~ m||) { $i++; if ($lines[$i] =~ m|Count.*Region|) { $table_header_found = 1 ; } elsif ($table_header_found) { $lines[$i] =~ m|(\d+)| ; $count = $1 ; $i++; while ($lines[$i] =~ m||) { $i++ ; } $lines[$i] =~ m|(.+)| ; $region_name = $1 ; if ($region_verified{$region_list_rev{$region_name}} != $count) { $region_verified{$region_list_rev{$region_name}} = $count ; $change = 1 ; } } } elsif ($lines[$i] =~ m||) { if ($table_header_found) { last ; } } elsif ($lines[$i] =~ m|Date: (.*) PST|) { $uptime = time_str_to_time($1); if ($uptime != $region_verified{'Time'}) { $change = 1 ; } } } if ($change) { if (defined($write_log)) { open(LOG, ">>$vlogfile"); print LOG "Time ",$uptime,"\n" ; for my $r (sort keys(%region_verified)) { if (!($r eq "Time")) { print LOG "$r $region_verified{$r}\n" ; } } close LOG ; } open(LOG, ">$vfile"); print LOG "Time ",$uptime,"\n" ; for my $r (sort keys(%region_verified)) { if (!($r eq "Time")) { print LOG "$r $region_verified{$r}\n" ; } } close LOG ; } } sub time_str_to_time { my ($ts) = @_ ; my ($day,$mon,$mday,$hour,$min,$sec,$year) = $ts =~ m|(\w+) +(\w+) +(\d+) +(\d+):(\d+):(\d+) +(\d+)| ; return timelocal($sec,$min,$hour,$mday,$month_list{$mon},$year) + 3 * 60 * 60 ; # PST to EST } sub candfilt { my ($page) = @_ ; my @lines = split (/\n/,$page) ; for (my $i = 0 ; $i < @lines ; $i++) { if ($lines[$i] =~ m|/nom/cp/(\d+)\.html\">(.+)|) { my $anchor = $lines[$i] ; chop $anchor ; my $candnum = $1 ; my $name = $2 ; $i++; $lines[$i] =~ m|- (\d+) endorsement|; my $endors = $1 ; $lines[$i] =~ m|(.*)|; my $twocountries = ($1 eq '*') ; $candlist[$num]->{name} = $name ; $candlist[$num]->{number} = $candnum ; my $name1 = $name ; $name1 =~ s/ /\ \;/g ; $candlist[$num]->{anchor} = "$name1" ; $candlist[$num]->{endors} = $endors ; $candlist[$num]->{twoCountries} = $twocountries ; $num++; } elsif ($lines[$i] =~ m|This page was last updated on: (.*)<|) { $last_icann_update =$1 ; # appears to be PST #$last_icann_update_time = timelocal(2,59,0,1,8,2000); $last_icann_update_time = time_str_to_time($last_icann_update); } } } sub candfiltfinal { my ($page) = @_ ; my @lines = split (/\n/,$page) ; my $num = 0 ; for (my $i = 2 ; $i < @lines ; $i++ ) { my ($candnum,$endors,$name) = split (" ",$lines[$i],3); $candlist[$i-2]->{name} = $name ; $candlist[$i-2]->{number} = $candnum ; my $name1 = $name ; $name1 =~ s/ /\ \;/g ; $candlist[$i-2]->{anchor} = "$name1" ; $candlist[$i-2]->{endors} = $endors ; #$candlist[$i-2]->{twoCountries} = $twocountries ; } } sub total_votes(@) { my (@cands) = @_ ; my $t = 0 ; for $c (@cands) { $t += $c->{endors}; } $t ; } sub by_endors { my $c = ($b->{endors} <=> $a->{endors}) ; if ($c == 0) { $a->{number} <=> $b->{number} ; } else { $c ; } } sub by_order { $a->{number} <=> $b->{number} ; } sub time_left { print "$t_Time_left:
\n" ; print "\n"; my $timeleft = $end_time - time; if ($timeleft > 0) { my ($secleft,$minleft,$hourleft,$dayleft,$t1,$t2,$t3,$t4) = gmtime($timeleft); $dayleft--; #print $dayleft," day" ; #print "s" if ($dayleft != 1); printf("%d:%02d:%02d",$hourleft + 24*$dayleft ,$minleft,$secleft) ; #print $hourleft + 24*dayleft , " hour" ; #print "s" if ($hourleft != 1); #print " $minleft minute" ; #print "s" if ($minleft != 1); #print " $secleft second" ; #print "s" if ($secleft != 1); } else { print "0:00:00" ; } print "\n"; print "

\n"; } ########## sub main ############################################### sub main { my $page = get_icann_page($region) ; candfiltfinal($page); #get_verified() ; if (defined($write_log)) { open(LOG, ">>$logdir/$region.log"); print LOG "Time: ",time,"\n" ; print LOG "TimeICANN: $last_icann_update_time\n" ; for my $c (@candlist) { print LOG "$c->{number} $c->{endors} $c->{name}\n" ; } close LOG ; } my @candsort ; if ($sort_by eq 'e') { @candsort = sort by_endors @candlist ; } elsif ($sort_by eq 'o') { @candsort = sort by_order @candlist ; } else { @candsort = @candlist ; } $tv = total_votes(@candlist); print header, start_html($title); print `cat icannnot-top.html` ; print `cat icannnot-el-top.html` ; if (defined($write_log)) { print "writing log\n"; } print '

ICANNnot.org · ',$heading,'

' ; print "

" ; print "\n$t_Final_day

" ; #print "\n$t_Based_on_last_ICANN_update_at

\n" ; for my $l (sort(keys(%lang_list))) { if (!($l eq $lang)) { print "\n $lang_list{$l} " ; } else { print "\n $lang_list{$l} " } } print $translate_request ; print "\n

$t_Change_region:" ; for my $r (sort(keys(%$region_list))) { if (!($r eq $region)) { print "\n $region_list->{$r} " ; } } #if ($last_icann_update_time > $end_time) { $last_icann_update_time = $end_time ; #} #if ($region_verified{'Time'} > $end_time) { $region_verified{'Time'} = $end_time ; #} my $time_fraction = ($last_icann_update_time - $start_time)/($end_time - $start_time); my $vtime = $region_verified{'Time'} - $region_verified0{'Time'} ; my $vtimetotal = $end_time - $region_verified0{'Time'} ; my $vdelta = $region_verified{$region}-$region_verified0{$region}; my $approx_verified = $region_verified_final{$region} ; #if (time > $end_time) { # $approx_verified = $region_verified0{$region} + $vdelta * ($end_time - $region_verified0{'Time'})/$vtime ; #} #else { # $approx_verified = $region_verified0{$region} + $vdelta * (time - $region_verified0{'Time'})/$vtime ; #} my $projected_verified = $region_verified_final{$region} ; print "\n" ; print "
\n" ; print "" ; print "" ; print "" ; print '" ; print "\n" ; print "" ; print "" ; print '" ; print '" ; print "\n" ; print "" ; print "" ; print '" ; print '" ; print "\n" ; print "" ; print "" ; print '" ; print '" ; print "\n" ; print "" ; print "" ; print '" ; print '" ; print "\n" ; print "" ; print "" ; print '" ; print '" ; print "\n" ; print "" ; print "" ; print '" ; print '" ; print "\n" ; my $projected_turnout = $tv/$time_fraction/$region_regs{$region} ; my $projected_turnout2 = $tv/$time_fraction/$projected_verified ; print "" ; print "" ; print '" ; print '" ; print "\n" ; print "
" ; print "$t_Region: " ; print "' ; print "$region_list->{$region}" ; print "
" ; print " " ; print "' ; print "$t_Registered" ; print "' ; print "$t_Verified" ; print "
" ; print "$t_Members_on_15_Aug: " ; print "' ; print $region_regs{$region} ; print "' ; print $region_verified0{$region} ; print "
" ; print "$t_Current_approx: " ; print "' ; print ' ' ; print "' ; print int($approx_verified) ; print "
" ; print "$t_Projected: " ; print "' ; print ' ' ; print "' ; print int($projected_verified) ; print "
" ; print "$t_Total_votes: " ; print "' ; print $tv ; print "' ; print $tv ; print "
" ; print "$t_Voter_Turnout_p: " ; print "' ; printf ("%5.2f%%",$tv/$region_regs{$region}*100) ; print "' ; printf ("%5.2f%%",$tv/$approx_verified*100) ; print "
" ; print "$t_Projected_Turnout_p: " ; print "' ; printf ("%5.2f%%",$projected_turnout*100) ; print "' ; printf ("%5.2f%%",$projected_turnout2*100) ; print "
\n" ; print "
\n" ; print $voter_information ; print "
\n" ; time_left(); print "

$sorted_by_list{$sort_by}.
\n"; for my $s (sort(keys(%sort_by_list))) { if (!($s eq $sort_by)) { print "  $sort_by_list{$s} " ; } } print "

\n" ; my @turnout_list = reverse sort(1,.5,.25,$projected_turnout2,$projected_turnout) ; my $num_col = $#turnout_list + 7 ; # Table of candidates ######################################################### # Table headers print "\n" ; print "" ; print "" ; print '" ; #print '" ; print '" ; print '" ; print "" ; my $now_thresh = int($approx_verified*.02+1-.0001) ; if ($now_thresh < 20) {$now_thresh = 20;} print '" ; my $guar_thresh = int($region_regs{$region}*.02+1-.0001) ; print '" ; print "\n" ; print "" ; for my $x (@turnout_list) { print '" ; } print "\n" ; # candidates for (my $i = 0; $i < @candsort; $i++) { if ((!($sort_by eq 'e') && !$i) || ($sort_by eq 'e' && $i == $region_limit{$region})){ print "\n"; } print "" ; print "" ; print "" ; #if ($candsort[$i]->{twoCountries}) { # print "" ; print "" ; print "" ; for my $x (@turnout_list) { if ($candsort[$i]->{endors}/$tv >= .02/$x) { if ($candsort[$i]->{endors}/$tv*$x*$projected_verified < 20) { print "" ; } if (($candsort[$i]->{endors}>= 20)&& ($candsort[$i]->{endors}/$approx_verified >=.02)) { print "" ; if ($candsort[$i]->{endors}>= $guar_thresh) { print "" ; print "\n" ; } print "
" ; # print " "x20 ; # to force minimum column width print "$t_Candidate" ; print "' ; print "$t_Endorsements" ; print "' ; #print "$t_Two_or_more_countries" ; #print "' ; print "$t_Percentage_of_total_endorsements" ; print "' ; print "$t_Percentage_of_verified_members" ; print "" ; print "$t_Projections_based_on_voter_turnout" ; print "' ; print "$t_If_elections_ended_now
($t_at_least $now_thresh)" ; print "
' ; if ($guar_thresh < 20) {$guar_thresh = 20;} print "$t_Guaranteed
($t_at_least $guar_thresh)" ; print "
' ; if ($x*100 == int($x*100)) { print $x*100,'%' ; } else { printf ("%4.1f%%",$x*100) ; } print "
$t_Maximum_of $region_limit{$region} $t_member_nominated_candidates_except_for_ties_in $region_list->{$region}
" ; print $candsort[$i]->{anchor} ; print "" ; print $candsort[$i]->{endors} ; print "" ; # print "$t_Yes" ; #} #else { # print "" ; # print "$t_No" ; #} #print "" ; printf ("%5.2f%%",$candsort[$i]->{endors}/$tv * 100) ; print "" ; printf ("%5.2f%%",$candsort[$i]->{endors}/$approx_verified * 100) ; print "" ; print "<20" ; } else { print "" ; print "$t_Yes" ; } } else { print "" ; print "$t_No" ; } print "" ; print "$t_Yes" ; } else { print "" ; print "$t_No" ; } print "" ; print "$t_Yes" ; } else { print "" ; print "$t_No" ; } print "
\n
" ; print $table_legend ; print "
\n" ; print "

$t_This_page_was_automatically_generated_on \n" ; print &ctime(time); print " EST.\n" ; print end_html; exit 0 ; }