You are not logged in.

#1 2013-08-13 07:55:29

nil
Member
Registered: 2012-10-15
Posts: 33

[SOLVED] Conky Mail Notification using a Bash Script

Hi there, I have conky piped into a dzen panel, and I'm trying to get conky to echo my unread mail count whenever the # is >0. It's just not working for me, and I was wondering what I did incorrectly.

I have the 3 following files.
~/.conkyrc

background yes
out_to_console yes
out_to_x no
update_interval 1

TEXT
${execi 60 /home/nil/mail-notify}

~/mail-notify

#! /bin/bash

gmail=$(python /home/nil/gmail.py)

if [ $gmail -gt 0 ]; then
    echo "$gmail"
fi

~/gmail.py

#!/usr/bin/env python

# This is a script that checkes the gmail unread count.

from urllib.request import FancyURLopener

username = 'myusername'
password  = 'mypasswd'

url = 'https://%s:%s@mail.google.com/mail/feed/atom' % (username, password)

opener = FancyURLopener()
page = opener.open(url)

contents = page.read().decode('utf-8')


ifrom = contents.index('<fullcount>') + 11
ito   = contents.index('</fullcount>')

unread = contents[ifrom:ito]

print(unread)

gmail.py was taken from the archwiki page, and I've confirmed it to be working (I censored my user name and password here). What gmail.py does is output an integer representing your unread mail count.

Similarly, Conky's code and the mail-notify script run fine. If I rewrite mail-notify's conditional to be "if [ 1 -gt 0 ]; then", then it will successfully output the unread mail count. Hence the problem lies in the scripting of the if condition. mail-notify should run gmail.py, if the output count is >0, then it should echo that number. Else it does nothing. Any help is appreciated!

Last edited by nil (2013-08-19 23:40:14)

Offline

#2 2013-08-13 08:01:43

jasonwryan
Forum & Wiki Admin
From: .nz
Registered: 2009-05-09
Posts: 18,829
Website

Re: [SOLVED] Conky Mail Notification using a Bash Script

Presumably the script is called gmail.py, not gmail1.py?


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Online

#3 2013-08-13 08:04:58

nil
Member
Registered: 2012-10-15
Posts: 33

Re: [SOLVED] Conky Mail Notification using a Bash Script

jasonwryan wrote:

Presumably the script is called gmail.py, not gmail1.py?

Oops, sorry, that was a typo when writing up this post.

Offline

#4 2013-08-13 08:07:58

jasonwryan
Forum & Wiki Admin
From: .nz
Registered: 2009-05-09
Posts: 18,829
Website

Re: [SOLVED] Conky Mail Notification using a Bash Script

What happens when you run the script from the terminal with debug on?


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Online

#5 2013-08-13 08:08:26

nil
Member
Registered: 2012-10-15
Posts: 33

Re: [SOLVED] Conky Mail Notification using a Bash Script

Wait, what am I kidding? That does work. Never mind I'm really silly. I simplified my problem down here to try to reproduce the problem down to its core, but it ended up solving it somewhere in the end.

Offline

Board footer

Powered by FluxBB