You are not logged in.

#1 2009-06-19 17:54:21

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Script that shows new mails from Google Apps account in conky

Hello guys,

I'm looking for a script that outputs the number of new mails I received from my Mail Account with Google Apps.

I've already found a script that works pretty well with the normal Gmail but not obviously not with Google Apps.

import os
import string

#Enter your username and password below within double quotes
# eg. username="username" and password="password"
username="username"
password="********"

com="wget -O - https://"+username+":"+password+"@mail.google.com/mail/feed/atom --no-check-certificate"

temp=os.popen(com)
msg=temp.read()
index=string.find(msg,"<fullcount>")
index2=string.find(msg,"</fullcount>")
fc=int(msg[index+11:index2])

if fc==0:
   print "0 new"
else:
   print str(fc)+" new"

My idea was to replace mail.google.com/mail/feed/atom with mail.google.com/a/domain.tld/feed/atom but I always get connection errors like this.

Connection to mail.google.com|209.85.135.16|:443... connected.
HTTP request sent, wait for answer... 401 Unauthorized
Connection to mail.google.com|209.85.135.16|:443... connected.
HTTP request sent, wait for answer... 401 Unauthorized
Authorisation failed.
Traceback (most recent call last):
  File "/home/orschiro/.scripts/mail.py", line 15, in <module>
    fc=int(msg[index+11:index2])
ValueError: invalid literal for int() with base 10: ''

Any suggestion what I could try?

Thank you in advance. smile

Last edited by orschiro (2009-06-19 17:55:07)

Offline

#2 2009-07-04 05:30:51

harpo
Member
Registered: 2009-05-14
Posts: 21

Re: Script that shows new mails from Google Apps account in conky

Here's a script I wrote that you might try. Not used it with google apps.

  #!/usr/bin/perl
  use strict;
  use warnings;

  use XML::Atom::Client;

  my $api = XML::Atom::Client->new;

  $api->username('username');
  $api->password('password');

  my $feed = $api->getFeed('https://mail.google.com/mail/feed/atom')
    or die ("Error: ", $api->errstr, "\n");

  print(scalar($feed->entries)||0, "\n");

http://tezcatz.blogspot.com/2009/07/sim … gmail.html

Offline

#3 2009-07-04 08:06:12

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: Script that shows new mails from Google Apps account in conky

Here is part of a script that I am using with my Google Apps domain. Should be easy to follow. Just edit the three variables at the top of the script. I prompt for the password at boot so it is not hard coded in the script. I use x11-ssh-askpass for this.

MAIL_URL = ['https://', 'mail.google.com', '/a/domain.com/feed/atom']

USERNAME = "user@domain.com"

PASSWD = "password"

def initMail():

    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()

    passman.add_password(None, MAIL_URL[1], USERNAME, PASSWD)

    authhandler = urllib2.HTTPBasicAuthHandler(passman)

    opener = urllib2.build_opener(authhandler)

    urllib2.install_opener(opener)

def checkMail():
    logging.debug("checkMail()")

    try:
        f = urllib2.urlopen("".join(MAIL_URL))

        doc = xml.dom.minidom.parseString(f.read())

        c  = doc.getElementsByTagName("fullcount")[0].firstChild.data

        return dzenH1("Mail: ") + c

    except urllib2.URLError as e:
        return dzenH1("Mail: ") + "URLError"

Offline

#4 2009-07-04 09:07:25

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Script that shows new mails from Google Apps account in conky

Hey thank you two. smile I'll try them.

@mikesd,

might it be possible to hand me out the complete script?

Greets

Offline

Board footer

Powered by FluxBB