news4 - RSS aggrigation system
修订版 | 78b336a87914f4d54834ee9d80eac895b0121b22 (tree) |
---|---|
时间 | 2012-10-02 05:50:51 |
作者 | hylom <hylom@hylo...> |
Commiter | hylom |
fix timestamp-compareing problem
@@ -4,6 +4,7 @@ | ||
4 | 4 | import re |
5 | 5 | |
6 | 6 | import feedparser |
7 | +import dateutil.parser | |
7 | 8 | from config import config as config, target_rss as target_rss |
8 | 9 | |
9 | 10 | class FeedFetcher(object): |
@@ -21,10 +22,12 @@ class FeedFetcher(object): | ||
21 | 22 | 'title': e.title, |
22 | 23 | 'link': e.link, |
23 | 24 | 'body': e.description, |
24 | - 'date': e.updated, | |
25 | + 'date': dateutil.parser.parse(e.updated), | |
25 | 26 | 'feed': self._feed, |
26 | 27 | 'tags': [], |
27 | 28 | } |
29 | + if entry['date'].tzinfo == None: | |
30 | + entry['date'] = entry['date'].replace(tzinfo=dateutil.tz.tzutc()) | |
28 | 31 | entries.append(entry) |
29 | 32 | return entries |
30 | 33 |
@@ -32,7 +32,11 @@ def main(): | ||
32 | 32 | tags[tag]['quoted_name'] = urllib.quote(tag.encode('utf-8')) |
33 | 33 | |
34 | 34 | # sort by date |
35 | - entries.sort(lambda x,y: -cmp(x["date"],y["date"])) | |
35 | + cmp_entries = (lambda x,y: 1 if (x["date"] < y["date"]) else -1) | |
36 | + entries.sort(cmp_entries) | |
37 | + | |
38 | + for e in entries: | |
39 | + print e["date"] | |
36 | 40 | |
37 | 41 | # Do rendering |
38 | 42 | params = {'tags':tags, 'page':{}} |
@@ -11,8 +11,8 @@ from config import config, target_rss | ||
11 | 11 | from propertizer import propertize |
12 | 12 | |
13 | 13 | def date_format(date): |
14 | - dt = dateutil.parser.parse(date) | |
15 | - return dt.strftime('%Y/%m/%d %H:%M') | |
14 | + #dt = dateutil.parser.parse(date) | |
15 | + return date.strftime('%Y/%m/%d %H:%M') | |
16 | 16 | |
17 | 17 | class Renderer(object): |
18 | 18 | def __init__(self): |