VSIDO Support > Conky
conky - Gmail new email information (perl version 1)
hakerdefo:
After fiddling with snakes (read Python) & gem hunting (read Ruby), finally I have found the pearl of wisdom to wash away the conky blues :D
First install these script dependencies,
--- Code: ---sudo apt-get install perl
sudo apt-get install libxml-simple-perl
sudo apt-get install libwww-perl
--- End code ---
Next copy-paste following code in your text-editor,
--- Code: ---#!/usr/bin/perl
use strict;
use XML::Simple;
use LWP::Simple;
my $u = $ARGV[0];
my $p = $ARGV[1];
my $xmldata = get("https://$u:$p\@mail.google.com/mail/feed/atom");
my $xml = new XML::Simple;
my $data = $xml->XMLin($xmldata);
my @arr = reverse sort keys %{$data->{'entry'}};
if (@arr != 0 ) {
print "[$u] :: New mails ". @arr ."\n";
my $n = 3;
$n = @arr if @arr < 3;
for(my $i = 0; $i < $n; $i++) {
my $title = substr $data->{'entry'}->{$arr[$i]}->{'title'}, 0, 45;
my $frm = substr $data->{'entry'}->{$arr[$i]}->{'author'}->{'name'}, 0, 30;
my $dt = substr $data->{'entry'}->{$arr[$i]}->{'modified'}, 0, 10;
print "\n";
print "From: $frm, Date: $dt\n";
print "$title\n";
}
print "\n";
} else {
print "No new mail..\n";
}
exit 0;
--- End code ---
Now by default this script will show the last three (3) unread mails. If you want to change this number, edit the following line in the script (line number 13),
--- Code: ---my $n = 3;
--- End code ---
Save the script with the name 'check-gmail.pl' somewhere in your $PATH and give it execute permissions,
--- Code: ---chmod 755 /path/to/check-gmail.pl
--- End code ---
Next open your .conkyrc in text-editor and add following line to call 'check-gmail.pl' via conky,
--- Code: ---execi 600 perl /path/to/check-gmail.pl "your_gmail_username" "your_gmail_password"
--- End code ---
Of-course you will need to replace "your_gmail_username" and "your_gmail_password" above with your Google username and password.
Tested-Okay & Satisfaction-Guaranteed 8)
In a bit of a hurry at the moment so no scrot as a proof-of-the-pudding :D
Cheers!!!
VastOne:
Seems to function all right but is only seeing and saying No New Mail even though I have unread email...
VastOne:
But when I have multiple unread emails it seems to work fine...
Will keep on testing
VastOne:
Testing results and script modifications
Scrot showing 6 Unread emails and setup to show 4 in the script: Works perfectly
Scrot showing 2 Unread emails and setup to show 4 in the script: Works perfectly
Scrot with only one email unread. Consistent with same number 7 all the time: Not working perfectly ...
Scrot showing conky when there are no emails: Works perfectly
VastOne:
I have also modified the script to show less detail and format the way I like to see it in Conky
Here is the modified version of
check-gmail.pl (must be executable)
--- Code: ---#!/usr/bin/perl
use strict;
use XML::Simple;
use LWP::Simple;
use Term::ANSIColor qw( colored );
my $u = $ARGV[0];
my $p = $ARGV[1];
my $xmldata = get("https://$u:$p\@mail.google.com/mail/feed/atom");
my $xml = new XML::Simple;
my $data = $xml->XMLin($xmldata);
my @arr = reverse sort keys %{$data->{'entry'}};
if (@arr != 0 ) {
#print "New Email(s) ". @arr ."\n";
print "". @arr ." New Email(s)\n";
my $n = 4;
$n = @arr if @arr < 4;
for(my $i = 0; $i < $n; $i++) {
my $title = substr $data->{'entry'}->{$arr[$i]}->{'title'}, 0, 45;
my $frm = substr $data->{'entry'}->{$arr[$i]}->{'author'}->{'name'}, 0, 30;
my $dt = substr $data->{'entry'}->{$arr[$i]}->{'modified'}, 0, 10;
print "\n";
print "$frm\n";
print "$title\n";
}
print "\n";
} else {
print "0 New Email(s)\n";
}
exit 0;
--- End code ---
@hakerdefo:
You'll notice a new line I have added
--- Code: ---use Term::ANSIColor qw( colored );
--- End code ---
I am working on getting a simple color change to the script and will post it when I figure it out
Edit: Updated the above script to address this:
I am also working on this line:
Instead of it saying
New Email(s) 2
I would rather have it be reversed
2 New Email(s)
but I am struggling to get it right
thank you for this one.. it is extremely close to perfect and workable enough to get there... I happen to really like perl so well done mate!
Navigation
[0] Message Index
[#] Next page
Go to full version