mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Adding timeout to icon fetching, and handling bad .ICOs
This commit is contained in:
parent
d4bed1399c
commit
c5d380ec3e
2 changed files with 13 additions and 4 deletions
|
@ -9,6 +9,7 @@ import operator
|
|||
import BmpImagePlugin, PngImagePlugin, Image
|
||||
from StringIO import StringIO
|
||||
from apps.rss_feeds.models import MFeedPage
|
||||
from utils.feed_functions import timelimit
|
||||
|
||||
HEADERS = {
|
||||
'User-Agent': 'NewsBlur Favicon Fetcher - http://www.newsblur.com',
|
||||
|
@ -21,20 +22,25 @@ class IconImporter(object):
|
|||
self.feed = feed
|
||||
self.force = force
|
||||
|
||||
@timelimit(30)
|
||||
def save(self):
|
||||
if not self.force and self.feed.icon.not_found:
|
||||
print 'Not found, skipping...'
|
||||
# print 'Not found, skipping...'
|
||||
return
|
||||
if not self.force and not self.feed.icon.not_found and self.feed.icon.icon_url:
|
||||
print 'Found, but skipping...'
|
||||
# print 'Found, but skipping...'
|
||||
return
|
||||
image, image_file, icon_url = self.fetch_image_from_page_data()
|
||||
if not image:
|
||||
image, image_file, icon_url = self.fetch(force=self.force)
|
||||
|
||||
if image:
|
||||
ico_image = self.load_icon(image_file)
|
||||
if ico_image: image = ico_image
|
||||
try:
|
||||
ico_image = self.load_icon(image_file)
|
||||
if ico_image: image = ico_image
|
||||
except ValueError:
|
||||
# print "Bad .ICO"
|
||||
pass
|
||||
image = self.normalize_image(image)
|
||||
color = self.determine_dominant_color_in_image(image)
|
||||
image_str = self.string_from_image(image)
|
||||
|
|
|
@ -347,6 +347,9 @@ class Dispatcher:
|
|||
icon_importer = IconImporter(feed, force=self.options['force'])
|
||||
try:
|
||||
icon_importer.save()
|
||||
except TimeoutError, e:
|
||||
logging.debug(' ---> [%-30s] Icon fetch timed out...' % (unicode(feed)[:30]))
|
||||
feed.save_page_history(556, 'Timeout', '')
|
||||
except Exception, e:
|
||||
logging.debug('[%d] ! -------------------------' % (feed_id,))
|
||||
tb = traceback.format_exc()
|
||||
|
|
Loading…
Add table
Reference in a new issue