feed|feeds: Update datafile format to version 2
authorW. Trevor King <wking@tremily.us>
Thu, 10 Jan 2013 16:05:48 +0000 (11:05 -0500)
committerW. Trevor King <wking@tremily.us>
Thu, 10 Jan 2013 16:11:14 +0000 (11:11 -0500)
We may want to store additional data about previously seen entries
besides our possibly auto-generated ID.  Convert the `seen` mapping
from:

  entry_id -> our_id

to:

  entry_id -> {'id': our_id}

Signed-off-by: W. Trevor King <wking@tremily.us>
rss2email/feed.py
rss2email/feeds.py

index a78afec97401dd121a9c60b4878ae8f3a956867b..73b182a3dcd26b3082f14044d5c2cba0494f1751 100644 (file)
@@ -401,7 +401,7 @@ class Feed (object):
         if isinstance(guid, dict):
             guid = guid.values()[0]
         if guid in self.seen:
-            if self.seen[guid] == id_:
+            if self.seen[guid]['id'] == id_:
                 _LOG.debug('already seen {}'.format(id_))
                 return  # already seen
         sender = self._get_entry_email(parsed=parsed, entry=entry)
@@ -774,6 +774,8 @@ class Feed (object):
             _LOG.debug('new message: {}'.format(message['Subject']))
             if send:
                 self._send(sender=sender, message=message)
-            self.seen[guid] = id_
+            if guid not in self.seen:
+                self.seen[guid] = {}
+            self.seen[guid]['id'] = id_
         self.etag = parsed.get('etag', None)
         self.modified = parsed.get('modified', None)
index c73c29f499c9984d6a93eccff9ee378e9b4ecd44..1f13e258c476f4dc08252a7139083edbc0cce861 100644 (file)
@@ -125,7 +125,7 @@ class Feeds (list):
 
     >>> tmpdir.cleanup()
     """
-    datafile_version = 1
+    datafile_version = 2
     datafile_encoding = 'utf-8'
 
     def __init__(self, configfiles=None, datafile=None, config=None):
@@ -321,6 +321,12 @@ class Feeds (list):
 
     def _upgrade_state_data(self, data):
         version = data.get('version', 'unknown')
+        if version == 1:
+            for feed in data['feeds']:
+                seen = feed['seen']
+                for guid,id_ in seen.items():
+                    seen[guid] = {'id': id_}
+            return data
         raise NotImplementedError(
             'cannot convert data file from version {} to {}'.format(
                 version, self.datafile_version))