Created
April 7, 2010 11:39
-
-
Save banthar/358781 to your computer and use it in GitHub Desktop.
reddit new message tray notify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use LWP::Simple; | |
use Gtk2::TrayIcon; | |
# touch last_date | |
# wget "http://www.reddit.com/static/mailgray.png" "http://www.reddit.com/static/mail.png" | |
# | |
# go to http://www.reddit.com/prefs/feeds/ and add your rss bellow | |
my $rss_url = 'http://www.reddit.com/message/inbox/.rss?feed=' ... ; | |
my $inbox_url = 'http://www.reddit.com/message/inbox/'; | |
sub trim($) | |
{ | |
my $string = shift; | |
$string =~ s/^\s+//; | |
$string =~ s/\s+$//; | |
return $string; | |
} | |
sub get_last_post_date($) | |
{ | |
my $xml=shift; | |
if( $xml =~ /<dc:date>([^<]*)<\/dc:date>/ ) | |
{ | |
return trim($1); | |
} | |
else | |
{ | |
return ""; | |
} | |
} | |
print "init\n"; | |
open(FD,"<last_date"); | |
my $last_date=<FD>; | |
close(FD); | |
Gtk2->init; | |
my $icon= Gtk2::TrayIcon->new("mail"); | |
my $new_mail=0; | |
my $no_mail_icon= Gtk2::Image->new_from_file ("mailgray.png"); | |
my $new_mail_icon= Gtk2::Image->new_from_file ("mail.png"); | |
my $eventbox = Gtk2::EventBox->new; | |
sub click() | |
{ | |
if($new_mail) | |
{ | |
$eventbox->remove($new_mail_icon); | |
$eventbox->add($no_mail_icon); | |
$eventbox->show_all; | |
$new_mail=0; | |
} | |
else | |
{ | |
system("x-www-browser '$inbox_url'"); | |
} | |
} | |
$eventbox->signal_connect( 'button_press_event', \&click ); | |
$icon->add($eventbox); | |
$eventbox->add($no_mail_icon); | |
$icon->show_all; | |
my $i=0; | |
sub check_for_mail() | |
{ | |
print "checking\n"; | |
my $content = get $rss_url; | |
my $date=get_last_post_date($content); | |
if($date ne $last_date) | |
{ | |
print $last_date."\n".$date."\n"; | |
$last_date=$date; | |
open(FD,">last_date"); | |
print FD $last_date; | |
close(FD); | |
if(!$new_mail) | |
{ | |
$eventbox->remove($no_mail_icon); | |
$eventbox->add($new_mail_icon); | |
$eventbox->show_all; | |
$new_mail=1; | |
} | |
print "New mail!!!\n"; | |
system("killall sauer_client"); | |
} | |
return 1; | |
} | |
sub check_for_mail2() | |
{ | |
check_for_mail(); | |
return 0; | |
} | |
Glib::Timeout->add( 1000*60*5, \&check_for_mail); | |
Glib::Timeout->add( 0, \&check_for_mail2); | |
Gtk2->main; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment