summaryrefslogtreecommitdiff
path: root/bucky2/rest/topsy-nndb-web.pl
diff options
context:
space:
mode:
Diffstat (limited to 'bucky2/rest/topsy-nndb-web.pl')
-rwxr-xr-xbucky2/rest/topsy-nndb-web.pl123
1 files changed, 123 insertions, 0 deletions
diff --git a/bucky2/rest/topsy-nndb-web.pl b/bucky2/rest/topsy-nndb-web.pl
new file mode 100755
index 0000000..c2f1e62
--- /dev/null
+++ b/bucky2/rest/topsy-nndb-web.pl
@@ -0,0 +1,123 @@
+#!/usr/bin/perl
+use lib "../lib";
+use Rest::Topsy;
+use Data::Dumper;
+my $topsy = new Rest::Topsy;
+
+my $tasks = load_task_history($topsy);
+
+my $matches = [];
+foreach my $task (@$tasks)
+ {
+ next if $task->{'date'} == -1;
+ foreach my $k (qw[all month week day hour])
+ {
+ $task->{$k} =~ s/K$/000/;
+ $task->{$k} =~ s/M$/000000/;
+ }
+ push @$matches, $task;
+ }
+our $task_count = scalar(@$tasks);
+our $match_count = scalar(@$matches);
+our $percent = sprintf "%0.1f%%", 100* ($match_count/$task_count);
+
+print "Pulled $match_count/$task_count ($percent complete)\n";
+
+print_report( "name", [(sort name_sort @$matches)] );
+print_report( "all", [(sort { for $k (qw[all month week day hour]) { return $b->{$k} <=> $a->{$k} || next } } @$matches)] );
+print_report( "month", [(sort { for $k (qw[month week day hour all]) { return $b->{$k} <=> $a->{$k} || next } } @$matches)] );
+print_report( "week", [(sort { for $k (qw[week day hour all month]) { return $b->{$k} <=> $a->{$k} || next } } @$matches)] );
+print_report( "day", [(sort { for $k (qw[day hour all month week]) { return $b->{$k} <=> $a->{$k} || next } } @$matches)] );
+print_report( "hour", [(sort { for $k (qw[hour all month week day]) { return $b->{$k} <=> $a->{$k} || next } } @$matches)] );
+sub print_report
+ {
+ my ($title, $matches) = @_;
+ my $out .= header($title);
+ foreach my $p (@$matches)
+ {
+ next unless $p->{$title};
+ $out .= "<tr>";
+ $out .= "<td align='right'>". $p->{'all'} ."</td>";
+ $out .= "<td align='right'>". $p->{'month'} ."</td>";
+ $out .= "<td align='right'>". $p->{'week'} ."</td>";
+ $out .= "<td align='right'>". $p->{'day'} ."</td>";
+ $out .= "<td align='right'>". $p->{'hour'} ."</td>";
+
+ my $nndb_url = sprintf("http://www.nndb.com/people/%03d/%09d/", $p->{'id'} % 997, $p->{'id'});
+ my $topsy_url = "http://topsy.com/search?q=" . $p->{'name'};
+ $out .= "<td align='left'><a href=\"$nndb_url\">". $p->{'name'} ."</a></td>";
+ $out .= "<td align='left'><a href=\"$topsy_url\">(topsy)</a></td>";
+ $out .= "</tr>";
+ }
+ $out .= footer();
+ $topsy->write_data("../tmp/nndb/".$title.".html", $out);
+ }
+sub header
+ { my $current = shift; my $out .= <<__HEADER__;
+<html>
+<head>
+<style type="text/css">
+<!--
+body {font-size: 13px; }
+th {font-size: 13px; text-align: left;}
+td {font-size: 13px; }
+td a {font-size: 16px; }
+td.topsy a {font-size: 16px;}
+td.topsy a {display: none;}
+td.bold { font-weight: bold; }
+-->
+</style>
+</head>
+<body>
+Pulled $match_count/$task_count ($percent complete)<br>
+<table border=0 cellpadding=0 cellspacing=5>
+<tbody>
+<tr>
+<th>
+__HEADER__
+ $out .= join "</th><th>", map { $current eq $_ ? "<b>$_</b>" : "<a href='$_.html'>$_</a>" } qw[all month week day hour];
+ $out .= "</th><th>name</th>";
+ $out .= "</th></tr>";
+ return $out;
+ }
+sub footer
+ { return "</tbody></table></body></html>"; }
+sub nice_date
+ {
+ my ($date) = @_;
+ $date =~ s/^_//;
+ $date =~ s/\.html$//;
+ return $date;
+ }
+sub load_task_history
+ {
+ my ($self) = @_;
+ my $data = $self->read_data('../tmp/nndb/tasks.txt');
+ my @lines = split "\n", $data;
+ my @keys = qw[id name date doppelganger all month week day hour];
+ my $tasks = [];
+ foreach my $line (@lines)
+ {
+ next unless $line;
+ my (@input) = split "\t", $line;
+ my $hash = {};
+ for (my $i = 0; $i < @input; $i++)
+ {
+ $hash->{$keys[$i]} = $input[$i];
+ }
+ push @$tasks, $hash;
+ }
+ return $tasks;
+ }
+sub name_sort
+ {
+ my $name_a = lc $a->{'name'};
+ my $name_b = lc $b->{'name'};
+ $name_a =~ s/\,.*$//;
+ $name_b =~ s/\,.*$//;
+ my $last_a = $name_a;
+ my $last_b = $hame_b;
+ $last_a =~ s/^.* //;
+ $last_b =~ s/^.* //;
+ return $last_a cmp $last_b || $name_a cmp $name_b;
+ }