Created
May 11, 2014 11:30
-
-
Save xavery/5510b5c212bf90eb66e7 to your computer and use it in GitHub Desktop.
a script to aggregate the televote scores from ESC 2014
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# run the following script to get all the needed html files for processing : | |
# for i in AL AM AT AZ BY BE DK EE MK FI FR GE DE GR HU IS IE IL IT LV LT MT MD \ | |
# ME NO PL PT RO RU SM SI ES SE CH NL UA GB; | |
# do wget -O "$i.html" "http://www.eurovision.tv/page/results?event=1893&voter=$i"; | |
# done | |
# and put them in the working directory of this script. | |
use strict; | |
use warnings; | |
use HTML::TreeBuilder 5 -weak; | |
my %place_pts = ( | |
1 => 12, | |
2 => 10, | |
3 => 8, | |
4 => 7, | |
5 => 6, | |
6 => 5, | |
7 => 4, | |
8 => 3, | |
9 => 2, | |
10 => 1 | |
); | |
sub place_to_pts | |
{ | |
if(defined($place_pts{$_[0]})) | |
{ | |
return $place_pts{$_[0]}; | |
} | |
else | |
{ | |
return 0; | |
} | |
} | |
my %points; | |
my @files = <*.html>; | |
for (@files) | |
{ | |
my $root = HTML::TreeBuilder->new_from_file($_); | |
$root->elementify(); | |
my @televote = $root->look_down('_tag', 'td', 'class', 'result', 'title', 'Tele aggr'); | |
for (@televote) | |
{ | |
my $parent = $_->parent(); | |
my $country_elem = $parent->look_down('_tag', 'td', 'class', 'country'); | |
my $country = $country_elem->as_text(); | |
$country =~ s/^\s+|\s+$//g; | |
if(defined($points{$country})) | |
{ | |
$points{$country} += place_to_pts($_->as_text()); | |
} | |
else | |
{ | |
$points{$country} = place_to_pts($_->as_text()); | |
} | |
} | |
} | |
my $place = 1; | |
for (sort {$points{$b} <=> $points{$a}} keys %points) | |
{ | |
print "$place. $_ - $points{$_}\n"; | |
++$place; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment