From: W. Trevor King Date: Thu, 10 Jan 2013 16:05:48 +0000 (-0500) Subject: feed|feeds: Update datafile format to version 2 X-Git-Tag: v3.0~22 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2ffaf52858ec0f1726354f94e533533be3034e40;p=rss2email.git feed|feeds: Update datafile format to version 2 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 --- diff --git a/rss2email/feed.py b/rss2email/feed.py index a78afec..73b182a 100644 --- a/rss2email/feed.py +++ b/rss2email/feed.py @@ -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) diff --git a/rss2email/feeds.py b/rss2email/feeds.py index c73c29f..1f13e25 100644 --- a/rss2email/feeds.py +++ b/rss2email/feeds.py @@ -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))