I have done a little refactoring of the script I use to pop-up messages when I get new messages from both Twitter and now Identi.ca too.
Comments on my bad scripting welcomed.
Comments on my bad scripting welcomed.
use strict;
use warnings;
use XML::Simple;
use Array::Diff;
use Data::Dumper;
use OfficeLaunch;
use IPC::Open3;
use LWP::UserAgent;
use English qw( -no_match_vars );
local $OUTPUT_AUTOFLUSH = 1;
use version; our $VERSION = qv('0.0.2');
# -----------------------------------------------------------
# parse_rss.pl
#
# Created by Lance Wicks ( www.lancewicks.com)
#
# This simple script polls Twitter and identica
# and lets you now if there are new posts via
# Snarl, using Snarl_CMD.
#
# -----------------------------------------------------------
print "Twitter & Identi.ca alerter Version:$VERSION\n\n";
my $twitter_url = 'http://twitter.com/statuses/friends_timeline/73963.rss';
my $twitter_user = 'USERNAME';
my $twitter_pass = 'PASS';
my $twitter_icon = 'c:\lwtemp\LH\twitter.png';
my $identica_url = 'http://identi.ca/lancew/all/rss';
my $identica_user = 'USER';
my $identica_pass = 'PASS';
my $identica_icon = 'c:\lwtemp\LH\speaker.png';
sub parse_feed{
my($feed,$id,$pass) = @_;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $feed);
$req->authorization_basic($id, $pass);
my $rss_new = $ua->request($req)->as_string;
return $rss_new;
}
sub compare_feeds{
my($old,$new,$icon) = @_;
my @old_feed = split /<item/, $old;
my @new_feed = split /<item/, $new;
my $diff = Array::Diff->diff( \@old_feed, \@new_feed );
if ($diff->count > 0){
foreach (reverse(@{$diff->added})) {
$_ =~ /<title>(.+)<\/title>/;
if ($1 =~ /^(.*?): (.*)/) {
print "\n$1\n";
my $cmd = "\"C:\\Program Files\\Snarl_CMD_0.1\\Snarl_CMD.exe\" snShowMessage 8 \"$1\" \"$2\" \"$icon\"";
my $pid = open3(my $wtr, my $rdr, my $err, $cmd);
my @response = <$rdr>;
}
}
}
}
print "Obtaining initial feeds...\n";
my $twitter_orig = parse_feed($twitter_url, $twitter_user, $twitter_pass);
my $identica_orig = parse_feed($identica_url, $identica_user, $identica_pass);
# -----------------------------------------------------
# MAIN LOOP
# -----------------------------------------------------
while(1) {
print "Pausing";
for (my $count = 200; $count >= 1; $count--) {
print ".";
sleep(1);
}
my $twitter_new = parse_feed($twitter_url, $twitter_user, $twitter_pass);
my $identica_new = parse_feed($identica_url, $identica_user, $identica_pass);
compare_feeds($twitter_orig,$twitter_new,$twitter_icon);
compare_feeds($identica_orig,$identica_new,$identica_icon);
$twitter_orig = $twitter_new;
$identica_orig = $identica_new;
} 
Calendar






