yolanda/trunk/tools/tagcloud.pl
josch 1968a6c066 tags are now seperated by spaces
git-svn-id: http://yolanda.mister-muffin.de/svn@208 7eef14d0-6ed0-489d-bf55-20463b2d70db
2007-12-18 00:41:02 +00:00

35 lines
724 B
Perl
Executable file

#!/usr/bin/perl -w
use DBI;
$database = 'yolanda';
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass);
$sth = $dbh->prepare("select subject from videos");
$sth->execute();
while(($subject) = $sth->fetchrow_array())
{
@subject = split(' ', $subject);
foreach my $val (@subject)
{
$val =~ s/^\s*(.*?)\s*$/$1/;
if(length($val) >= 4)
{
%hash->{$val}++;
}
}
}
$sth->finish();
@sorted = sort {$hash{$b} cmp $hash{$a}} keys %hash;
$dbh->do("delete from tagcloud");
$sth = $dbh->prepare("insert into tagcloud (text, count) values (?, ?)");
for($i=0;$i<20 and $i<=$#sorted;$i++)
{
$sth->execute( $sorted[$i], %hash->{$sorted[$i]} );
}