use iterators

This commit is contained in:
Christophe Benz 2010-03-11 11:37:54 +01:00 committed by Christophe Benz
commit 9cb692a888
5 changed files with 11 additions and 10 deletions

View file

@ -25,5 +25,5 @@ class AuMBackend(Backend, ICapMessages, ICapMessagesReply):
def __init__(self, weboob):
Backend.__init__(self, weboob)
def getNewMessages(self, thread=None):
def iter_messages(self, thread=None):
pass

View file

@ -20,11 +20,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from weboob.backend import Backend
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply, Message
from feeds import ArticlesList
class DLFPBackend(Backend, ICapMessages, ICapMessagesReply):
def __init__(self, weboob):
Backend.__init__(self, weboob)
def getNewMessages(self, thread=None):
m = Message('threadid', 'msgid', 'Title', 'Sender', signature='Bite bite bite bite', content='Content content\nContent content.')
return [m]
def iter_messages(self, thread=None):
articles_list = ArticlesList('newspaper')
for id, author, title in articles_list.iter_articles():
yield Message('threadid', id, title, author, signature='Bite bite bite bite', content='Content content\nContent content.')

View file

@ -47,7 +47,7 @@ class ArticlesList:
self.section = section
self.articles = []
def fetch(self):
def iter_articles(self):
for section, klass in self.RSS.iteritems():
if self.section and self.section != section:
continue
@ -61,4 +61,4 @@ class ArticlesList:
continue
_id = m.group(1)
article = klass(_id, item['link'], item['title'], item['author'], item['date_parsed'])
print _id, item['author'], item['title']
yield _id, item['author'], item['title']

View file

@ -73,7 +73,7 @@ class Message:
return self.new
class ICapMessages:
def getNewMessages(self, thread=None):
def iter_messages(self, thread=None):
"""
Get new messages from last time this function has been called.

View file

@ -59,9 +59,8 @@ class Application(BaseApplication):
def process(self):
backends = self.weboob.getBackends()
for name, b in backends.iteritems():
messages = b.getNewMessages()
for m in messages:
self.send_email(name, m)
for message in b.iter_messages():
self.send_email(name, message)
def send_email(self, backend_name, mail):
domain = self.config['domain']