Skip to content

Instantly share code, notes, and snippets.

@aanoaa
Created January 22, 2011 12:15
Show Gist options
  • Save aanoaa/791080 to your computer and use it in GitHub Desktop.
Save aanoaa/791080 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent;
use AnyEvent::HTTP;
use LWP::Simple;
use Data::Dumper;
use DateTime::Format::W3CDTF;
use DBI;
use File::Temp;
use JSON;
my $seconds = 300;
my $dbfile = 'misc/poll.db';
#my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
my $starttime = scalar time;
my $lastest_time = 0;
my $file;
my $interval = 5;
#my $sth_insert = $dbh->prepare("insert into messages values (?, ?, 0, ?)");
#$sth_insert->execute('rss_atom', $issue_time, $message);
#my $temp = get "http://me2day.net/api/get_posts/aanoaa.json";
#print $temp, "\n";
my $cv = AnyEvent->condvar;
my $w; $w = AnyEvent->timer(
after => 10,
interval => $interval,
cb => sub {
my $data = get "http://me2day.net/api/get_posts/aanoaa.json";
my $content = from_json($data);
print "Check... $lastest_time\n";
for my $tweet (@{ $content }) {
my $out = $tweet->{textBody};
$tweet->{pubDate} =~ s/0900$/09:00/;
if ($tweet->{media}{photoUrl}) {
my $url = $tweet->{media}{photoUrl};
my $uri = URI->new($url);
next unless $uri->scheme && $uri->scheme =~ /^http/i;
next unless $uri->authority;
if (length "$uri" > 50 && $uri->authority !~ /tinyurl|bit\.ly/) {
$url = makeashorterlink($uri);
}
$out .= ' ' . $url;
}
my $dt = DateTime::Format::W3CDTF->parse_datetime($tweet->{pubDate});
#$dt->epoch;
if ($dt->epoch > $lastest_time and $dt->epoch > $starttime) {
$lastest_time = $dt->epoch;
print $out;
#$sth_insert->execute('rss_atom', scalar time, $out);
}
}
}
);
$cv->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment