From e76b691e78e273226cba9284cb8cd22a423319ed Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 2 Aug 2013 17:23:25 -0500 Subject: bucky2 --- bucky2/rest/topsy-nndb-web.pl | 123 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100755 bucky2/rest/topsy-nndb-web.pl (limited to 'bucky2/rest/topsy-nndb-web.pl') 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 .= ""; + $out .= "". $p->{'all'} .""; + $out .= "". $p->{'month'} .""; + $out .= "". $p->{'week'} .""; + $out .= "". $p->{'day'} .""; + $out .= "". $p->{'hour'} .""; + + 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 .= "". $p->{'name'} .""; + $out .= "(topsy)"; + $out .= ""; + } + $out .= footer(); + $topsy->write_data("../tmp/nndb/".$title.".html", $out); + } +sub header + { my $current = shift; my $out .= <<__HEADER__; + + + + + +Pulled $match_count/$task_count ($percent complete)
+ + + +"; + $out .= ""; + return $out; + } +sub footer + { return "
+__HEADER__ + $out .= join "", map { $current eq $_ ? "$_" : "$_" } qw[all month week day hour]; + $out .= "name
"; } +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; + } -- cgit v1.2.3-70-g09d2