summaryrefslogtreecommitdiff
path: root/bucky2/rest/dropsy.pl
blob: c986abef515a14f45b853309b9afd5c102f7d5a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/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,
			};
		$is_ffa = 0;
		if (exists($topsy_map->{$title}))
			{
			$rec->{'topsy'} = $topsy_map->{$title},
			}
		push @$dr_topsy_match, $rec;
		}
	}

# foreach my $p (sort { $b->{'date'} cmp $a->{'date'} } @$dr_topsy_match)
# foreach my $p (sort { $b->{'topsy'} <=> $a->{'topsy'} } @$dr_topsy_match)
 foreach my $p (sort { $b->{'forum'} <=> $a->{'forum'} } @$dr_topsy_match)
	{
	#next if $p->{'ffa'};
	if ($p->{'ffa'}) { $p->{'forum'} .= "*"; }
	print
		$p->{'date'} . "\t" .
		$p->{'forum'} . "\t" .
		$p->{'topsy'} . "\t" .
		$p->{'title'} . "\n";
	}

sub nice_date
	{
	my ($date) = @_;
	$date =~ s/^_//;
	$date =~ s/\.html$//;
	return $date;
	}