3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-25 21:39:27 +01:00
pbot/modules/gtop15.pl
Pragmatic Software 73b793295b todo! add support for admin management - needs support for adding/removing/saving!
todo! multi-channel support pathetic (note 12/08/09, fixed multi-channel for anti-flood and for ignore)
todo! most of this crap needs to be refactored (note 11/23/09, refactored execute_module)

0.4.1 (12/08/09): improved anti-flood system to be significantly more accurate and per-channel
                  added per-nick-per-channel message history using %flood_watch
                  add per-channel support to ignore system
                  automatically remove message history for nicks that haven't spoken in one day (run once per hour)
                  do not ignore !login command
0.3.16(11/23/09): refactored module execution to execute_module() subroutine
                  added trigger to execute get_title.pl module when URL is
                  detected in regular untriggered chat
0.3.15(11/20/09): replace 'me' with '$nick' in arguments
2009-12-09 01:08:12 +00:00

109 lines
1.8 KiB
Perl
Executable File

#!/usr/bin/perl -w -I /home/msmud/lib/lib/perl5/site_perl/5.10.0/
use LWP::Simple;
my $html;
if($#ARGV < 0)
{
print "Usage: !gtop15 country\n";
exit 0;
}
my $country = join " ", @ARGV;
$country = lc $country;
$html = get("http://www.google.com/press/intl-zeitgeist.html");
defined $html or die "Oops, couldn't get the data.";
my %countries;
while($html =~ m/<a href="#(.*?)" class="style10">(.*?)<\/a>/g)
{
$countries{$1} = $2;
}
my $found = 0;
if(not defined $countries{$country})
{
foreach my $c (values %countries)
{
if(lc $c eq $country)
{
$found = 1;
$country = $c;
last;
}
}
}
else
{
$found = 1;
}
if($found == 0)
{
print "Unknown country, valid countries are ";
foreach my $c (sort keys %countries)
{
print "$c,";
}
exit 0;
}
my %countries2;
if(length($country) == 2)
{
%countries2 = %countries;
}
else
{
%countries2 = reverse %countries;
}
print "Top 15 Google search queries ($countries2{$country}): ";
$country = $countries2{$country} if(length($country) == 2);
$html =~ m/<td colspan="3"\s*class="zeit_monthly_head">.*?<b>\s*$country\s*<\/b>/gms;
my $i = 15;
while($html =~ m/<a href=".*?"\s*class="zeit_link">\s*(.*?)\s*<\/a>(.*?)<\/li>/gms)
{
my $result = $1;
if(length $2)
{
$2 =~ m/<span\s*class="zeit_small_txt">\s*(.*?)<\/span>/;
$result = $1;
}
else
{
$result=~s/[^\t -~]//g;
# print "[[$1]]\n";
# my $p = $1;
# $result = "";
# while($p =~ m/(.)/g)
# {
# print $1 . "[" . ord($1) . "]";
# next;
# if(ord($1) > 122)
# {
# $p =~ m/./g;
# next;
# }
# next if(ord($1) < 97 && ord($1) > 122 && ord($1) < 65 && ord($1) > 90
# && ord($1) < 48 && ord($1) > 57);
# $result .= $1;
# }
}
print "$result, ";
last if(--$i == 0);
}