• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

news4 - RSS aggrigation system


Commit MetaInfo

Revision35706daeb11067ffac8035502714bda9c6752ef0 (tree)
Zeit2013-04-26 04:09:15
Autorhylom <hylom@hylo...>
Commiterhylom

Log Message

fix: crash when RSS item is invalid

Ändern Zusammenfassung

Diff

--- a/fetcher.py
+++ b/fetcher.py
@@ -8,6 +8,12 @@ import dateutil.parser
88 from config import config as config
99 from logger import log
1010
11+def _get_attr(obj, attr, default=""):
12+ try:
13+ return obj.__getattr__(attr)
14+ except AttributeError:
15+ return default
16+
1117 class FeedFetcher(object):
1218 'Feed fetching and parsing'
1319 def __init__(self, feed):
@@ -18,21 +24,26 @@ class FeedFetcher(object):
1824 f = feedparser.parse(self._feed["source"])
1925 entries = []
2026 for e in f['entries']:
21- try:
22- desc = e.description
23- except AttributeError:
24- desc = ''
27+
2528 entry = {
26-# 'title': e.title.decode('utf8') if isinstance(e.title, str) else e.title,
27- 'title': e.title,
28- 'url': e.link,
29- 'body': desc,
30- 'date': dateutil.parser.parse(e.updated),
3129 'feed': self._feed,
3230 'tags': [],
3331 }
32+ entry["title"] = _get_attr(e, "title", "(no title)")
33+ entry["url"] = _get_attr(e, "link")
34+ entry["body"] = _get_attr(e, "description")
35+ entry["date"] = _get_attr(e, "updated", None)
36+
37+ if entry["date"] == None:
38+ entry["date"] = _get_attr(e, "published", None)
39+
40+ if entry["date"] == None:
41+ continue
42+
43+ entry["date"] = dateutil.parser.parse(entry["date"])
3444 if entry['date'].tzinfo == None:
3545 entry['date'] = entry['date'].replace(tzinfo=dateutil.tz.tzutc())
46+
3647 entries.append(entry)
3748 return entries
3849