plutopluto

git clone https://git.ce9e.org/plutopluto.git

commit
d6a925bbdbfdedc79626cd48cc1214aae3578118
parent
d647a2feab5a08e2d9062312910d6711e663f411
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2014-12-26 10:30
preserve sort order if no timestamp is provided

Diffstat

M plutopluto/__init__.py 11 +++++++----

1 files changed, 7 insertions, 4 deletions


diff --git a/plutopluto/__init__.py b/plutopluto/__init__.py

@@ -37,10 +37,13 @@ def parse(url):
   37    37 
   38    38 	feed = feedparser.parse(url)
   39    39 
   40    -1 	def _parse_item(item):
   -1    40 	def _parse_item(args):
   -1    41 		i, item = args
   41    42 		d = dict()
   42    -1 		d['dt'] = (mktime(item['published_parsed']) if 'published_parsed' in item
   43    -1 			else int(time()))
   -1    43 		if 'published_parsed' in item:
   -1    44 			d['dt'] = mktime(item['published_parsed'])
   -1    45 		else:
   -1    46 			d['dt'] = int(time()) - i  # - i to preserve sort order
   44    47 		d['id'] = item.get('id')
   45    48 		d['title'] = item.get('title')
   46    49 		d['link'] = item.get('link')
@@ -56,7 +59,7 @@ def parse(url):
   56    59 
   57    60 	return {
   58    61 		'url': url,
   59    -1 		'entries': map(_parse_item, feed.entries),
   -1    62 		'entries': map(_parse_item, enumerate(feed.entries)),
   60    63 	}
   61    64 
   62    65