Commit 9cb692a8 authored by Christophe Benz's avatar Christophe Benz Committed by Christophe Benz

use iterators

parent 0ac4885a
......@@ -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
......@@ -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.')
......@@ -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']
......@@ -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.
......
......@@ -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']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment