You are not logged in.
Pages: 1
I need some way to check the gmail, that just gives me the number of unread mail. Is there any scripts for that?
Offline
Sure.
#!/usr/bin/env python2
import os
import string
#Enter your username and password below within double quotes
# eg. username="username" and password="password"
username="username"
password="absolutelybrilliantpassword"
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"
I have this script feeding my DWM statusbar with info, but I don't really remember where I got it from, as I only have it saved as gmail.py
edit: OK, knopwob beat me to it! And as bonus I got to know where I got the script from
Last edited by Onyros (2012-07-26 11:44:48)
Offline
Nice gmail script. Is it safe to run this (quering gmail) every second for use with dwm statusbar?
Offline
I use it with DWM, but the script "sleeps" for 5 seconds.
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
delim=" | ";
while true; do
freq=`sed 8q /proc/cpuinfo | awk '/cpu MHz/{print int($4)}'`;
memtotal=`awk '/MemTotal/{print $2}' < /proc/meminfo`;
memcached=`sed 4q /proc/meminfo | awk '/Cached/{print $2}'`;
membuffers=`awk '/Buffers/{print $2}' < /proc/meminfo`;
memory=$(( $memtotal/1024 ));
memfree=`awk '/MemFree/{print $2}' < /proc/meminfo`;
memfreez=$(( ($memtotal-$memfree) ));
freemem=$(( ($memfreez-$membuffers-$memcached)/1024 ));
battery=`acpi`;
ctime=`date '+%a, %d %b %H:%M'`;
weather=`curl -s --connect-timeout 10 http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=1\&locCode\="EUR|PT|PO012|Lisbon" \ | sed -n '/Currently:/ s/.*: \(.*\): \([-0-9]*\)\([CF]\).*/\2°\3, \1/p'`;
mail=`python2 ~/.scripts/gmail.py 2>/dev/null 2>/dev/null`
xsetroot -name "CPU: ${freq}MHz${delim}$freemem MiB / $memory MiB${delim}$battery${delim}$ctime${delim}${weather}${delim}Mail: ${mail}"
sleep 5;
done
It's actually just checking the RSS feed, shows up on Gmail's activity as Atom Feed access type. For me, it's much lighter than conky and has all information I want available easily.
Offline
Offline
I modified the gmail script to loop with 5 min sleep and write the value to file (useful with dwm statusbar written in C):
#!/usr/bin/env python2
import os
import time
import string
username = "foo"
password = "faa"
outfile = "/home/herman/log/nmails"
com = 'curl -s -u "{}:{}" https://mail.google.com/mail/feed/atom'.format(username, password)
interval = 300 # seconds
while True:
temp = os.popen(com)
msg = temp.read()
index = string.find(msg, "<fullcount>")
index2 = string.find(msg, "</fullcount>")
fc = int(msg[index + 11 : index2])
f = open(outfile, "w")
f.write(str(fc))
f.close()
time.sleep(interval);
Last edited by hesse (2012-07-26 22:10:18)
Offline
I just made a python 3 compatible script like the ones above, except it doesnt use wget:
#!/usr/bin/env python
# encoding: utf-8
from urllib.request import FancyURLopener
username = 'username'
password = 'superlongandhardpassword'
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)
Last edited by Paaskehare (2012-07-30 21:40:42)
→ im.ole
Offline
Offline
found a small application, html2text So Im doing like this at the moment,
wget -O mail.html - 'https://user:pass@mail.google.com/mail/feed/atom'
html2text mail.html|awk '/New/ {print $7}'
Offline
I just made a python 3 compatible script like the ones above, except it doesnt use wget:
#!/usr/bin/env python # encoding: utf-8 from urllib.request import FancyURLopener username = 'username' password = 'superlongandhardpassword' 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)
works very well! tnx!
Offline
It's actually just checking the RSS feed, shows up on Gmail's activity as Atom Feed access type. For me, it's much lighter than conky and has all information I want available easily.
Offline
Pages: 1