diff options
| author | Jules Laplace <carbon@melanarchy.org> | 2013-08-02 17:23:25 -0500 |
|---|---|---|
| committer | Jules Laplace <carbon@melanarchy.org> | 2013-08-02 17:23:25 -0500 |
| commit | e76b691e78e273226cba9284cb8cd22a423319ed (patch) | |
| tree | a58d22f69869fe2bf3885f81bdda4952f87ff6d7 /bucky2/rest | |
| parent | 753f60c7d4769fa72d3b910e491f37db6f130898 (diff) | |
bucky2
Diffstat (limited to 'bucky2/rest')
| -rwxr-xr-x | bucky2/rest/coin-toss.pl | 66 | ||||
| -rwxr-xr-x | bucky2/rest/dailyrotten.pl | 6 | ||||
| -rwxr-xr-x | bucky2/rest/dropsy-web.pl | 103 | ||||
| -rwxr-xr-x | bucky2/rest/dropsy.pl | 56 | ||||
| -rwxr-xr-x | bucky2/rest/goathead.pl | 67 | ||||
| -rwxr-xr-x | bucky2/rest/lemmingtrail-sendspace.pl | 71 | ||||
| -rwxr-xr-x | bucky2/rest/sendspace-single.pl | 70 | ||||
| -rwxr-xr-x | bucky2/rest/sendspace.pl | 71 | ||||
| -rwxr-xr-x | bucky2/rest/topsy-display.pl | 12 | ||||
| -rwxr-xr-x | bucky2/rest/topsy-nndb-web.pl | 123 | ||||
| -rwxr-xr-x | bucky2/rest/topsy-nndb.pl | 109 | ||||
| -rwxr-xr-x | bucky2/rest/topsy.pl | 7 |
12 files changed, 761 insertions, 0 deletions
diff --git a/bucky2/rest/coin-toss.pl b/bucky2/rest/coin-toss.pl new file mode 100755 index 0000000..875590c --- /dev/null +++ b/bucky2/rest/coin-toss.pl @@ -0,0 +1,66 @@ +#!/usr/bin/perl +use lib "../lib"; +use Rest::Twitter; +use Data::Dumper; +my $twitter = new Rest::Twitter; +$twitter->auth("coin_toss","onetimeonly"); + +while (1) + { + my $tweets = $twitter->tweet_get(); +print Dumper($tweets); + foreach my $tweet (@$tweets) + { + my $toss = coin_toss_tweet($twitter, $tweet); + if ($toss) + { + print "$tweet->{'user'}: $tweet->{'tweet'}\n"; + if ($tweet->{'type'} eq "dm") + { + $twitter->dm_post($tweet->{'user'}, $toss); + } + else + { + $twitter->tweet_post("@" . $tweet->{'user'} . " " . $toss, $tweet->{'id'}); + } + } + } + sleep 60; + } +sub coin_toss_tweet + { + my ($twitter, $tweet) = @_; + my $user = $twitter->user; + my $msg = $tweet->{'tweet'}; + my $toss = undef; + return undef if $tweet->{'user'} eq $user; + $msg =~ s/\@$user:?//g; + $msg =~ s/\?*$//g; + if ($msg =~ /rock/i && $msg =~ /paper/i && $msg =~ /scissors/i) + { + $toss = coin_toss("rock", "paper", "scissors"); + } + elsif ($msg =~ /\sor\s/i) + { + my (@faces) = split " or ", $msg; + $toss = coin_toss(@faces); + } + elsif ($msg =~ /\//i) + { + my (@faces) = split "/", $msg; + $toss = coin_toss(@faces); + } + else + { + $toss = coin_toss("heads", "tails"); + } + return $toss; + } +sub coin_toss + { + my (@faces) = @_; + my $face = uc $faces[ int rand scalar @faces ]; + my $face_string = join "/", @faces; + return "$face_string: $face"; + } +1; diff --git a/bucky2/rest/dailyrotten.pl b/bucky2/rest/dailyrotten.pl new file mode 100755 index 0000000..bf21933 --- /dev/null +++ b/bucky2/rest/dailyrotten.pl @@ -0,0 +1,6 @@ +#!/usr/bin/perl +use lib "../lib"; +use Rest::Dailyrotten; +my $dr = new Rest::Dailyrotten; +$dr->dailyrotten_get; +exit; diff --git a/bucky2/rest/dropsy-web.pl b/bucky2/rest/dropsy-web.pl new file mode 100755 index 0000000..af2304d --- /dev/null +++ b/bucky2/rest/dropsy-web.pl @@ -0,0 +1,103 @@ +#!/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 .= "<tr>"; + $out .= "<td align='right'>". $p->{'date'} ."</td>"; + + my $ffa_class = " bold" if $p->{'ffa'}; + $out .= "<td align='right' class='$ffa_class'>". $p->{'forum'} ."</td>"; + + my $topsy_class = " bold" if $p->{'topsy'} > 100; + $out .= "<td align='right' class='topsy$topsy_class'>". $p->{'topsy'} ."</td>"; + + $out .= "<td align='left'><a href=\"$p->{'url'}\">". $p->{'title'} ."</a></td>"; + $out .= "</tr>"; + } + $out .= footer(); + $topsy->write_data("../tmp/dr/".$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> +<b>date</b> = date posted on <a href="http://www.dailyrotten.com/">daily rotten</a> = date twittered<br> +<b>forum</b> = comments on dailyrotten forum (FFAs are bold)<br> +<b>topsy</b> = number of other people tweeting this story as calculated by <a href="http://topsy.com/twitter/dailyrotten">topsy</a><br> +<b>title</b> = title of article<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[date forum topsy title]; + $out .= "</th></tr>"; + return $out; + } +sub footer + { return "</tbody></table></body></html>"; } +sub nice_date + { + my ($date) = @_; + $date =~ s/^_//; + $date =~ s/\.html$//; + return $date; + } diff --git a/bucky2/rest/dropsy.pl b/bucky2/rest/dropsy.pl new file mode 100755 index 0000000..c986abe --- /dev/null +++ b/bucky2/rest/dropsy.pl @@ -0,0 +1,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; + } diff --git a/bucky2/rest/goathead.pl b/bucky2/rest/goathead.pl new file mode 100755 index 0000000..347dfae --- /dev/null +++ b/bucky2/rest/goathead.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl +use lib "../lib"; +use Rest::Twitter; +use Data::Dumper; +my $twitter = new Rest::Twitter; +$twitter->auth("goatflayer","onetimeonly"); +my $url_file = "../tmp/goat-data.txt"; +my $tweet_file = "../tmp/goat-tweet.txt"; + +while (1) + { + my $which = int rand 10; + if ($which < 6) + { + my $tweet = get_next_tweet($url_file); + if ($tweet) + { + $twitter->tweet_post("#nsfw #tasteless " . $tweet); + sleep 3600*(5+rand(5)); + } + else + { print "\n\n\n\nNo more tweets!\n"; exit; } + } + else + { + my $tweet = get_next_tweet($tweet_file); + if ($tweet) + { + $twitter->tweet_post($tweet); + sleep 600 * (4+rand(4)); + } + } + } + +sub coin_toss + { + my (@faces) = @_; + my $face = uc $faces[ int rand scalar @faces ]; +# my $face_string = join "/", @faces; + return $face; + } +sub get_next_tweet + { + my ($file) = @_; + open TWEETS, $file; + my @tweets = <TWEETS>; + close TWEETS; + my $picked = int rand scalar @tweets; + my $tweet = ''; + open TWEETS, ">$file"; + for (my $i = 0; $i < scalar @tweets; $i++) + { + if ($i == $picked) + { + $tweet = $tweets[$i]; + chomp $tweet; + } + else + { + print TWEETS $tweets[$i]; + } + } + close TWEETS; + return $tweet; + } +1; + diff --git a/bucky2/rest/lemmingtrail-sendspace.pl b/bucky2/rest/lemmingtrail-sendspace.pl new file mode 100755 index 0000000..4ee5041 --- /dev/null +++ b/bucky2/rest/lemmingtrail-sendspace.pl @@ -0,0 +1,71 @@ +#!/usr/bin/perl +use lib "../lib"; +use Rest; +my $browser = new Rest; +my $BIN_WGET = "/usr/bin/wget"; +my ($WGET_SINGLE, $WGET_WEBPAGE) = & make_wget_commands; + +my @sendspace_urls = & lemmingtrail_urls; +foreach my $sendspace_url (@sendspace_urls) + { + my ($url_dl) = & sendspace_get($sendspace_url); + & dl($url_dl); + } +exit; +sub dl + { + my ($url) = @_; + return unless $url; + system($WGET_SINGLE . " " . $url); + } +sub lemmingtrail_urls + { + my $lemmingtrail_url = "http://www.lemmingtrail.com/mb/207771/"; + my $content = $browser->rest_get_raw($lemmingtrail_url); + my @urls = & html_scrape_urls($content, "sendspace.com"); + return @urls; + } +sub sendspace_get + { + my ($sendspace_url) = @_; + return unless $sendspace_url; + my $content = $browser->rest_post_raw($sendspace_url, {download=>" REGULAR DOWNLOAD "}); + print "got content: " . length($content) . " bytes\n"; + my @urls = & html_scrape_urls($content, "sendspace.com/dl"); + return @urls; + } +sub html_scrape_urls + { + my ($content, $valid_url_match) = @_; + my @lines = split "<a", $content; + my @urls = (); + foreach my $line (@lines) + { + next unless $line =~ /href=/; + $line =~ /href="([^"]+)"/; + # http://fs05n5.sendspace.com/dl/181e8d00c2955c7862d9a0d559c12cf1/4ade166e37a8af6c/bwbz9y/Sporelec.zip + my $url = $1; + next unless $url =~ /$valid_url_match/; + print "URL: " . $url ."\n"; + push @urls, $url; + } + return @urls; + } +sub make_wget_commands + { + my $ua = ("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705)"); + my $dp = $PROJECT || "wgetdir"; + + # -E = --html-extension + # -H = --span-hosts + # -k = --convert-links + # -K = --backup-converted + # -p = --page-requisite + + my $SINGLE = "$BIN_WGET -erobots=off --user-agent='$ua' --directory-prefix=$dp"; + my $WEBPAGE = "$BIN_WGET -erobots=off -d -o wgetlog " . + "--user-agent='$ua' -E -H -K -k -p --no-directories " . + "--directory-prefix=$dp"; + return ($SINGLE, $WEBPAGE); + } +1; diff --git a/bucky2/rest/sendspace-single.pl b/bucky2/rest/sendspace-single.pl new file mode 100755 index 0000000..8d5e074 --- /dev/null +++ b/bucky2/rest/sendspace-single.pl @@ -0,0 +1,70 @@ +#!/usr/bin/perl +use lib "../lib"; +use Rest; +my $browser = new Rest; +my $BIN_WGET = "/usr/bin/wget"; +my ($WGET_SINGLE, $WGET_WEBPAGE) = & make_wget_commands; + +foreach my $sendspace_url (@ARGV) + { + my ($url_dl) = & sendspace_get($sendspace_url); + & dl($url_dl); + } +exit; +sub dl + { + my ($url) = @_; + return unless $url; + system($WGET_SINGLE . " " . $url); + } +sub lemmingtrail_urls + { + my $lemmingtrail_url = "http://www.lemmingtrail.com/mb/207771/"; + my $content = $browser->rest_get_raw($lemmingtrail_url); + my @urls = & html_scrape_urls($content, "sendspace.com"); + return @urls; + } +sub sendspace_get + { + my ($sendspace_url) = @_; + return unless $sendspace_url; + my $content = $browser->rest_post_raw($sendspace_url, {download=>" REGULAR DOWNLOAD "}); + print "got content: " . length($content) . " bytes\n"; + my @urls = & html_scrape_urls($content, "sendspace.com/dl"); + return @urls; + } +sub html_scrape_urls + { + my ($content, $valid_url_match) = @_; + my @lines = split "<a", $content; + my @urls = (); + foreach my $line (@lines) + { + next unless $line =~ /href=/; + $line =~ /href="([^"]+)"/; + # http://fs05n5.sendspace.com/dl/181e8d00c2955c7862d9a0d559c12cf1/4ade166e37a8af6c/bwbz9y/Sporelec.zip + my $url = $1; + next unless $url =~ /$valid_url_match/; + print "URL: " . $url ."\n"; + push @urls, $url; + } + return @urls; + } +sub make_wget_commands + { + my $ua = ("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705)"); + my $dp = $PROJECT || "wgetdir"; + + # -E = --html-extension + # -H = --span-hosts + # -k = --convert-links + # -K = --backup-converted + # -p = --page-requisite + + my $SINGLE = "$BIN_WGET -erobots=off --user-agent='$ua' --directory-prefix=$dp"; + my $WEBPAGE = "$BIN_WGET -erobots=off -d -o wgetlog " . + "--user-agent='$ua' -E -H -K -k -p --no-directories " . + "--directory-prefix=$dp"; + return ($SINGLE, $WEBPAGE); + } +1; diff --git a/bucky2/rest/sendspace.pl b/bucky2/rest/sendspace.pl new file mode 100755 index 0000000..4ee5041 --- /dev/null +++ b/bucky2/rest/sendspace.pl @@ -0,0 +1,71 @@ +#!/usr/bin/perl +use lib "../lib"; +use Rest; +my $browser = new Rest; +my $BIN_WGET = "/usr/bin/wget"; +my ($WGET_SINGLE, $WGET_WEBPAGE) = & make_wget_commands; + +my @sendspace_urls = & lemmingtrail_urls; +foreach my $sendspace_url (@sendspace_urls) + { + my ($url_dl) = & sendspace_get($sendspace_url); + & dl($url_dl); + } +exit; +sub dl + { + my ($url) = @_; + return unless $url; + system($WGET_SINGLE . " " . $url); + } +sub lemmingtrail_urls + { + my $lemmingtrail_url = "http://www.lemmingtrail.com/mb/207771/"; + my $content = $browser->rest_get_raw($lemmingtrail_url); + my @urls = & html_scrape_urls($content, "sendspace.com"); + return @urls; + } +sub sendspace_get + { + my ($sendspace_url) = @_; + return unless $sendspace_url; + my $content = $browser->rest_post_raw($sendspace_url, {download=>" REGULAR DOWNLOAD "}); + print "got content: " . length($content) . " bytes\n"; + my @urls = & html_scrape_urls($content, "sendspace.com/dl"); + return @urls; + } +sub html_scrape_urls + { + my ($content, $valid_url_match) = @_; + my @lines = split "<a", $content; + my @urls = (); + foreach my $line (@lines) + { + next unless $line =~ /href=/; + $line =~ /href="([^"]+)"/; + # http://fs05n5.sendspace.com/dl/181e8d00c2955c7862d9a0d559c12cf1/4ade166e37a8af6c/bwbz9y/Sporelec.zip + my $url = $1; + next unless $url =~ /$valid_url_match/; + print "URL: " . $url ."\n"; + push @urls, $url; + } + return @urls; + } +sub make_wget_commands + { + my $ua = ("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705)"); + my $dp = $PROJECT || "wgetdir"; + + # -E = --html-extension + # -H = --span-hosts + # -k = --convert-links + # -K = --backup-converted + # -p = --page-requisite + + my $SINGLE = "$BIN_WGET -erobots=off --user-agent='$ua' --directory-prefix=$dp"; + my $WEBPAGE = "$BIN_WGET -erobots=off -d -o wgetlog " . + "--user-agent='$ua' -E -H -K -k -p --no-directories " . + "--directory-prefix=$dp"; + return ($SINGLE, $WEBPAGE); + } +1; diff --git a/bucky2/rest/topsy-display.pl b/bucky2/rest/topsy-display.pl new file mode 100755 index 0000000..88d4976 --- /dev/null +++ b/bucky2/rest/topsy-display.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use lib "../lib"; +use Rest::Topsy; +my $topsy = new Rest::Topsy; +$topsy->url('http://twitter.com/dailyrotten'); +my $entries = $topsy->topsy_load; + +foreach my $entry (sort { $b->{'total'} <=> $a->{'total'} } @$entries) + { + print $entry->{'total'} ."\t".$entry->{'date'}. "\t" . $entry->{'description'} ."\n"; + } + 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; + } diff --git a/bucky2/rest/topsy-nndb.pl b/bucky2/rest/topsy-nndb.pl new file mode 100755 index 0000000..c749a71 --- /dev/null +++ b/bucky2/rest/topsy-nndb.pl @@ -0,0 +1,109 @@ +#!/usr/bin/perl +use lib "../lib"; +use Rest::Topsy; +use Data::Dumper; +my $topsy = new Rest::Topsy; + +#my $tasks = initialize_names($topsy); +#save_task_history($topsy, $tasks); +#exit; + +my $tasks = load_task_history($topsy); +#print Dumper($tasks); +#exit; +my $i = 0; +# foreach my $task (sort {$a->{'date'} <=> $b->{'date'}} @$tasks) +foreach my $task (sort task_sort @$tasks) + { + my $tracking_data = $topsy->topsy_search($task->{'name'}); + foreach my $k (keys %$tracking_data) + { $task->{$k} = $tracking_data->{$k}; } + $task->{'date'} = time; + if ($i++ == 20) + { + save_task_history($topsy, $tasks); + $i = 0; + } + sleep 35 + (int rand 20); + } +save_task_history($topsy, $tasks); + +exit; + +sub task_sort + { + $b->{'hour'} <=> $a->{'hour'} || + $b->{'day'} <=> $a->{'day'} || + $b->{'week'} <=> $a->{'week'} || + $b->{'month'} <=> $a->{'month'} || + $b->{'all'} <=> $a->{'all'} || + $a->{'date'} <=> $b->{'date'} + } +sub initialize_names + { + my ($self) = @_; + my $data = $self->read_data('../tmp/nndb/all-names-living.txt'); + my @lines = split "\n", $data; + my $names = {}; + foreach my $line (@lines) + { + next unless $line; + my ($id, $name) = split "\t", $line; + if (exists ($names->{$name})) + { $names->{$name} = -1 * $id; } + else + { $names->{$name} = $id; } + } + my $tasks = []; + foreach my $name (keys %$names) + { + my $hash = {}; + $hash->{'id'} = abs $names->{$name}; + $hash->{'name'} = $name; + $hash->{'date'} = -1; + if ($names->{$name} < 1) + { + $hash->{'doppelganger'} = 1; + } + push @$tasks, $hash; + } + return $tasks; + } +sub save_task_history + { + my ($self, $tasks) = @_; + my @keys = qw[id name date doppelganger all month week day hour]; + my @lines; + foreach my $task (@$tasks) + { + my @input; + for (my $i = 0; $i < @keys; $i++) + { + push @input, $task->{$keys[$i]}; + } + my $line = join "\t", @input; + push @lines, $line; + } + my $data = join "\n", @lines; + $self->write_data("../tmp/nndb/tasks.txt", $data); + } +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; + } diff --git a/bucky2/rest/topsy.pl b/bucky2/rest/topsy.pl new file mode 100755 index 0000000..eb05535 --- /dev/null +++ b/bucky2/rest/topsy.pl @@ -0,0 +1,7 @@ +#!/usr/bin/perl +use lib "../lib"; +use Rest::Topsy; +my $topsy = new Rest::Topsy; +$topsy->url('http://twitter.com/dailyrotten'); +$topsy->topsy_get; +exit; |
