Skip to content

Commit

Permalink
Issue #6: fix missing title while subscribing directly to a feed URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
passiomatic committed Mar 14, 2015
1 parent 2a10aa9 commit 9463bf6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion coldsweat/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def feed_worker(feed):
# Each worker has its own connection
connect()
fetcher = Fetcher(feed)
fetcher.fetch_feed()
fetcher.update_feed()



Expand Down
21 changes: 11 additions & 10 deletions coldsweat/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def handle_200(self, response):
handle_302 = handle_200 # Alias


def fetch_feed(self):
def update_feed(self):

logger.debug(u"fetching %s" % self.netloc)
logger.debug(u"updating %s" % self.netloc)

# Check freshness
for value in [self.feed.last_checked_on, self.feed.last_updated_on]:
Expand Down Expand Up @@ -153,8 +153,8 @@ def fetch_feed(self):
self.feed.last_status = status
logger.warn(u"%s replied with status %d, aborted" % (self.netloc, status))
return
self.parse_feed(response.text)
self.fetch_icon()
self._parse_feed(response.text)
self._fetch_icon()
except (HTTPError, HTTPNotModified, DuplicatedFeedError):
return # Bail out
finally:
Expand All @@ -163,8 +163,12 @@ def fetch_feed(self):
logger.warn(u"%s has accomulated too many errors, disabled" % self.netloc)
self.feed.is_enabled = False
self.feed.save()

def parse_feed(self, data):

def update_feed_with_data(self, data):
self._parse_feed(data)
self.feed.save()

def _parse_feed(self, data):

soup = feedparser.parse(data)
# Got parsing error?
Expand All @@ -177,8 +181,6 @@ def parse_feed(self, data):
self.feed.alternate_link = ft.get_alternate_link()
self.feed.title = self.feed.title or ft.get_title() # Do not set again if already set

#self.feed.save()

entries = []
feed_author = ft.get_author()

Expand Down Expand Up @@ -228,7 +230,7 @@ def parse_feed(self, data):
return entries


def fetch_icon(self):
def _fetch_icon(self):

if not self.feed.icon or not self.feed.icon_last_updated_on or (self.instant - self.feed.icon_last_updated_on).days > FETCH_ICONS_DELTA:
# Prefer alternate_link if available since self_link could
Expand All @@ -237,7 +239,6 @@ def fetch_icon(self):
self.feed.icon_last_updated_on = self.instant

logger.debug(u"fetched favicon %s..." % (self.feed.icon[:70]))
#self.feed.save()


def _google_favicon_fetcher(self, url):
Expand Down
9 changes: 5 additions & 4 deletions coldsweat/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,11 @@ def feed_add_1(self):

# It's a feed

#@@TODO: add plugin events
feed = self.add_feed_from_url(self_link, fetch_data=False)
ff = Fetcher(feed)
ff.parse_feed(response.text)
feed = self.add_feed_from_url(self_link, fetch_data=False)
logger.debug(u"starting fetcher")
trigger_event('fetch_started')
Fetcher(feed).update_feed_with_data(response.text)
trigger_event('fetch_done', [feed])

return self._add_subscription(feed, group_id)

Expand Down

0 comments on commit 9463bf6

Please sign in to comment.