#!/usr/bin/perl use lib "../lib"; use Rest::Topsy; use Rest::Dailyrotten; my $topsy = new Rest::Topsy; my $dr = new Rest::Dailyrotten; $topsy->url('http://twitter.com/dailyrotten'); my $entries = $topsy->topsy_load; my $stories = $dr->dailyrotten_load; my $topsy_map = {}; map { $topsy_map->{$_->{'description'}} = $_->{'total'} } @$entries; my $dr_topsy_match = []; foreach my $day (@$stories) { my $is_ffa = 1; foreach my $story (reverse @{ $day->{'post'} }) { my $title = $story->{'title'}; my $rec = { date => nice_date($day->{'file'}), title => $title, forum => $story->{'comments'}, ffa => $is_ffa, url => $story->{'url'}, }; $is_ffa = 0; if (exists($topsy_map->{$title})) { $rec->{'topsy'} = $topsy_map->{$title}, } push @$dr_topsy_match, $rec; } if ($dr_topsy_match->[-1]->{'forum'} > 100) { $dr_topsy_match->[-1]->{'ffa'} = 1; } } print_report("title", [(sort { lc $a->{'title'} cmp lc $b->{'title'} } @$dr_topsy_match)]); print_report("date", [(sort { $b->{'date'} cmp $a->{'date'} } @$dr_topsy_match )]); print_report("topsy", [(sort { $b->{'topsy'} <=> $a->{'topsy'} } @$dr_topsy_match)]); print_report("forum", [(sort { $b->{'forum'} <=> $a->{'forum'} } @$dr_topsy_match)]); sub print_report { my ($title, $matches) = @_; my $out .= header($title); foreach my $p (@$matches) { $out .= ""; $out .= "". $p->{'date'} .""; my $ffa_class = " bold" if $p->{'ffa'}; $out .= "". $p->{'forum'} .""; my $topsy_class = " bold" if $p->{'topsy'} > 100; $out .= "". $p->{'topsy'} .""; $out .= "{'url'}\">". $p->{'title'} .""; $out .= ""; } $out .= footer(); $topsy->write_data("../tmp/dr/".$title.".html", $out); } sub header { my $current = shift; my $out .= <<__HEADER__; date = date posted on daily rotten = date twittered
forum = comments on dailyrotten forum (FFAs are bold)
topsy = number of other people tweeting this story as calculated by topsy
title = title of article
"; return $out; } sub footer { return "
__HEADER__ $out .= join "", map { $current eq $_ ? "$_" : "$_" } qw[date forum topsy title]; $out .= "
"; } sub nice_date { my ($date) = @_; $date =~ s/^_//; $date =~ s/\.html$//; return $date; }