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): def __init__(self, weboob):
Backend.__init__(self, weboob) Backend.__init__(self, weboob)
def getNewMessages(self, thread=None): def iter_messages(self, thread=None):
pass 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.backend import Backend
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply, Message from weboob.capabilities.messages import ICapMessages, ICapMessagesReply, Message
from feeds import ArticlesList
class DLFPBackend(Backend, ICapMessages, ICapMessagesReply): class DLFPBackend(Backend, ICapMessages, ICapMessagesReply):
def __init__(self, weboob): def __init__(self, weboob):
Backend.__init__(self, weboob) Backend.__init__(self, weboob)
def getNewMessages(self, thread=None): def iter_messages(self, thread=None):
m = Message('threadid', 'msgid', 'Title', 'Sender', signature='Bite bite bite bite', content='Content content\nContent content.') articles_list = ArticlesList('newspaper')
return [m] 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.section = section
self.articles = [] self.articles = []
def fetch(self): def iter_articles(self):
for section, klass in self.RSS.iteritems(): for section, klass in self.RSS.iteritems():
if self.section and self.section != section: if self.section and self.section != section:
continue continue
@ -61,4 +61,4 @@ class ArticlesList:
continue continue
_id = m.group(1) _id = m.group(1)
article = klass(_id, item['link'], item['title'], item['author'], item['date_parsed']) 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 return self.new
class ICapMessages: class ICapMessages:
def getNewMessages(self, thread=None): def iter_messages(self, thread=None):
""" """
Get new messages from last time this function has been called. Get new messages from last time this function has been called.

View file

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