cleared alt-text for thumbnails

don't break when content-type isn't returned
don't break on bad if-modified-since headers
log failed image requests
This commit is contained in:
shuffman
2008-07-02 20:33:59 -07:00
parent bcca862eaa
commit a7a3669e4b
5 changed files with 21 additions and 10 deletions

View File

@@ -148,10 +148,10 @@ class Globals(object):
#setup the logger
self.log = logging.getLogger('reddit')
self.log.addHandler(logging.StreamHandler())
if self.debug:
self.log.setLevel(logging.DEBUG)
self.log.addHandler(logging.StreamHandler())
def __del__(self):
"""
Put any cleanup code to be run when the application finally exits

View File

@@ -57,15 +57,20 @@ def make_link_info_job(results, link, useragent):
link's thumbnail and media object. Places the result in the results
dict"""
def job():
scraper = make_scraper(link.url)
try:
scraper = make_scraper(link.url)
thumbnail = scraper.thumbnail()
media_object = scraper.media_object()
thumbnail = scraper.thumbnail()
media_object = scraper.media_object()
if thumbnail:
upload_thumb(link, thumbnail)
if thumbnail:
upload_thumb(link, thumbnail)
results[link] = (thumbnail, media_object)
except:
log.warning('error fetching %s %s' % (link._fullname, link.url))
raise
results[link] = (thumbnail, media_object)
return job
def update_link(link, thumbnail, media_object):

View File

@@ -69,6 +69,9 @@ def fetch_url(url, referer = None, retries = 1, dimension = False):
content = open_req.read()
content_type = open_req.headers.get('content-type')
if not content_type:
return nothing
if 'image' in content_type:
p = ImageFile.Parser()
new_data = content

View File

@@ -12,7 +12,10 @@ def read_http_date(date_str):
try:
date = datetime.strptime(date_str, DATE_RFC850)
except ValueError:
date = datetime.strptime(date_str, DATE_ANSI)
try:
date = datetime.strptime(date_str, DATE_ANSI)
except ValueError:
return None
date = date.replace(tzinfo = pytz.timezone('GMT'))
return date

View File

@@ -197,7 +197,7 @@
<%def name="thumbnail()">
%if thing.thumbnail:
<%call expr="make_link('thumbnail', 'thumbnail')">
<img src="${thing.thumbnail}" alt="thumbnail for ${thing._fullname}"/>
<img src="${thing.thumbnail}" alt=""/>
</%call>
%endif
</%def>