![]() | Compartimos un pequeño programa escrito en Python cuyo objetivo es verificar la cantidad de emails sin leer de una cuenta de Gmail. Espero lo disfruten... |
Otro aporte de Luis López lo convierte en uno de los ganadores de nuestra competencia semanal: "Compartí lo que sabés sobre Linux". ¡Felicitaciones Luis!
Atención: es necesario instalar notify-send para que el programa funcione correctamente.
En caso de que deseen descargarlo, el código fuente que se despliega a continuación se encuentra disponible en github: https://gist.github.com/3910908
#!/usr/bin/env python
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###########################################################
# Created by Luis Lopez <luislopez72@gmail.com>
# GmailPypy v1.0
# note: You must install notify-send.
###########################################################
from urllib2 import Request, urlopen
from base64 import encodestring
from re import search
from os import system
# GMail Credentials
user = "tu_usuario@gmail.com"
passwd = "tu_password:)"
# Create the request object and add the Authorization header
request = Request( "https://mail.google.com/mail/feed/atom" )
base64str = encodestring( "%s:%s" % (user, passwd)).replace( "\n", "")
request.add_header( "Authorization", "Basic %s" % base64str )
# Get the GMail athom response
try:
response = urlopen( request )
except:
response = None
msg = "Error inesperado al obtener la informacion. Verifique su conexion o las credenciales de GMail por favor."
# Get the number of unreaded Emails
if response is None:
matched = None
else:
matched = search( r"<fullcount>(?P<unreaded>\d+)</fullcount>", response.read() )
# Create a message to be displayed
if matched is None or int( matched.group("unreaded") ) == 0:
msg = None
else:
msg = "He encontrado " + str( matched.group("unreaded") ) + " email(s) sin leer"
# Show a Pop-up notification with the message
if msg is None:
pass
else:
notify = "notify-send -u normal 'GMail\n %s'" % msg
system( notify )
No olviden editar el valor de las variables user y passwd con su usuario de gmail y su contraseña.
En caso que deseen agragarlo a crontab:
1.- Abren el archivo de crontab de su usuario (mi usuario es lucho)
crontab -u lucho -e
2.- Lo editan agregando una linea como esta y guardan
*/10 * * * * env DISPLAY=:0.0 /ruta/al/archivo/pygmail.py
Esto hará que el programa se ejecute una vez cada 10 minutos, y el pop-up aparecerá en el DISPLAY=:0.0.
¡Gracias Luis López!
¿Querés participar en nuestra competencia mensual y hacer un aporte a la comunidad?
Sólo tenés que enviarnos un correo incluyendo el truco o mini-tutorial de tu autoría.
Sólo tenés que enviarnos un correo incluyendo el truco o mini-tutorial de tu autoría.

