Python Tidbits
PythonTextToSpeech
tray icon app wxPython
http://mail.python.org/pipermail/python-list/2003-January/141014.html
http://radio.weblogs.com/0110159/gems/systray_py.txt
wxWindows and twisted event loop:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/181780
check mail:
#adapted from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52299
#thanks Brent Burley
import imaplib,string,getpass,rfc822,os,re,sys
class msg:
def __init__(self,text):
self.lines=string.split(text,'\015\012')
self.lines.reverse()
def readline(self):
try: return self.lines.pop() + '\n'
except: return ''
class Mailwatcher:
def getmail(self):
answer={}
self.passwd="<PASSWORD>"
try:
M=imaplib.IMAP4()
M.login(getpass.getuser(),self.passwd)
except Exception, e:
print "Imap error %s" % e
return
try:
result,message=M.select(readonly=1)
if result !='OK':
raise Exception, message
typ, data=M.uid('search',None,'(UNSEEN UNDELETED)')
for num in string.split(data[0]):
try:
f=M.uid('fetch',num,'(UID BODY[HEADER.FIELDS (SUBJECT FROM)])')
m=rfc822.Message(msg(f[1][0][1]),0)
subject=m['subject']
except KeyError:
f=M.uid('fetch',num,'(UID BODY[HEADER.FIELDS (FROM)])')
m=rfc822.Message(msg(f[1][0][1]),0)
subject='(no subject)'
fromaddr=m.getaddr('from')
if fromaddr[0]=="":n=fromaddr[1]
else: n=fromaddr[0]
text = '%-20.20s %s' % (n,subject)
msgline= "UID: %s"% num + " from: %s" %n + " Subject: %s " %subject
if answer.has_key(num):
pass
else:
answer[num]=msgline
except:
pass
M.logout()
return answer
mw=Mailwatcher()
list=mw.getmail()
for num in list:
print list[num]
Uses:
ManiacBot can use it via JabberMessaging to notify of new mail arrival. Part of the PersonalBotProject
|