Tuesday, March 17, 2009

Backend For Panel Reminder

I had already posted about creating a Display Reminders In Gnome Panel. This post is an addition to that script. This is a backend script that writes what to print into the panel_remind file. I use this script to print Birthday Reminder and Things to remember of which I will be posting shortly.
So the Code is simple Perl script.
#!/usr/bin/perl
our $printl;our $i=0;our $r=0;
$| = 1;
while(TRUE)
{
open (RB,"/home/rsrijith/perl/reminder");
my @line=<RB>;
close RB;
if($line[0])
{
while($line[$i])
{
open (WR,">/home/rsrijith/panel_remind");
my @s=split(":",$line[$i]);
my $nowtime=timelocal(localtime());
my $a=$s[2]+300;
if(($s[0]-$nowtime<=$a)&&($s[0]-$nowtime>=0))
{
my $t= to_int((($s[0]-$nowtime)/60));
while($t>0)
{
open (WR,">/home/rsrijith/panel_remind");
print WR "Red:In $t Mins - $s[3]";
close WR;
$r=1;
$t--;
sleep(60);
if( $t == 0)
{ `notify-send "$s[3]" -u critical -t 60000`}
}
}
open (WB,">/home/rsrijith/perl/reminder");
my $nowtime=timelocal(localtime());
if($s[0]-$nowtime>0)
{
print WB "$line[$i]";
close WB;
}
$i++;

}
if($r eq 0)
{
bday();
}
$i=0;
}
else
{
print "Birthday";
bday();
}
}


sub bday
{
open (RB,"/home/rsrijith/shell/birthdays");
my @line=<RB>;
close RB;

if((!$line[0])&&($r==0))
{
print "nothing to remind";
$printl="Black:Nothing to Remind \n:(";
open (WR,">/home/rsrijith/panel_remind");
print WR $printl;
close WR;
sleep(100);
}
while($line[$i])
{
$_=$line[$i];
if(m/Happy/)
{
$printl="Blue:$line[$i]";
}
else
{
$printl="Black:$line[$i]";
}
open (WR,">/home/rsrijith/panel_remind");
print WR $printl;
close WR;
$i++;
sleep(5);
}
$i=0;
return;
}
This script reads from files
  • /home/rsrijith/shell/birthdays: The file contains birthdays of my friends that I need to be reminded of. The method to print the upcoming birthdays into this file is posted at <will be posted soon>.
  • /home/rsrijith/perl/reminder:The file contains reminders that I need to  be reminded. I used another script to write into that file which is posted at <will be posted soon >.
This program needs libnotify  package. The package name is libnotify1 in my computer. It may vary with linux you are in.



So the ordinary panel reminder can be made of some use using this script.
So try it out and tell me how it went.

No comments:

Post a Comment