Embed images in html output.

This commit is contained in:
Bastian Kleineidam 2013-03-09 21:39:43 +01:00
parent 8b0a523f77
commit 75e576f2de
3 changed files with 19 additions and 15 deletions

View file

@ -7,6 +7,7 @@ Features:
Changes: Changes:
- cmdline: Comic lists are now displayed one page at a time. - cmdline: Comic lists are now displayed one page at a time.
- events: HTML output now embeds the images in the page.
Fixes: Fixes:
- cmdline: Catch error when piping output to another - cmdline: Catch error when piping output to another

View file

@ -98,5 +98,5 @@ class ComicImage(object):
raise raise
else: else:
out.info("Saved %s (%s)." % (fn, strsize(size))) out.info("Saved %s (%s)." % (fn, strsize(size)))
getHandler().comicDownloaded(self.name, fn) getHandler().comicDownloaded(self, fn)
return fn, True return fn, True

View file

@ -70,12 +70,13 @@ class RSSEventHandler(EventHandler):
def comicDownloaded(self, comic, filename): def comicDownloaded(self, comic, filename):
"""Write RSS entry for downloaded comic.""" """Write RSS entry for downloaded comic."""
url = self.getUrlFromFilename(filename) imageUrl = self.getUrlFromFilename(filename)
title = '%s - %s' % (comic, os.path.basename(filename)) title = '%s - %s' % (comic.name, os.path.basename(filename))
description = '<img src="%s"/><br/><a href="%s">View Comic</a>' % (url, url) pageUrl = comic.referrer
description = '<img src="%s"/><br/><a href="%s">View Comic</a>' % (imageUrl, pageUrl)
args = ( args = (
title, title,
url, imageUrl,
description, description,
util.rfc822date(time.time()) util.rfc822date(time.time())
) )
@ -125,31 +126,33 @@ class HtmlEventHandler(EventHandler):
self.html.write(u'''<!DOCTYPE html> self.html.write(u'''<!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="generator" content="%s"/>
<title>Comics for %s</title> <title>Comics for %s</title>
</head> </head>
<body> <body>
<a href="%s">Previous Day</a> | <a href="%s">Next Day</a> <a href="%s">Previous Day</a> | <a href="%s">Next Day</a>
<ul> <ul>
''' % (time.strftime('%Y/%m/%d', today), yesterdayUrl, tomorrowUrl)) ''' % (configuration.App, time.strftime('%Y/%m/%d', today),
yesterdayUrl, tomorrowUrl))
self.lastComic = None self.lastComic = None
def comicDownloaded(self, comic, filename): def comicDownloaded(self, comic, filename):
"""Write HTML entry for downloaded comic.""" """Write HTML entry for downloaded comic."""
if self.lastComic != comic: if self.lastComic != comic.name:
self.newComic(comic) self.newComic(comic)
url = self.getUrlFromFilename(filename) imageUrl = self.getUrlFromFilename(filename)
self.html.write(u'<li><img src="%s"/></li>\n' % url) pageUrl = comic.referrer
self.html.write(u'<li><a href="%s"><img src="%s"/></a></li>\n' % (pageUrl, imageUrl))
def newComic(self, comic): def newComic(self, comic):
"""Start new comic list in HTML.""" """Start new comic list in HTML."""
if self.lastComic is not None: if self.lastComic is not None:
self.html.write(u' </ul>\n') self.html.write(u'</ul>\n')
self.lastComic = comic self.lastComic = comic.name
self.html.write(u''' <li>%s</li> self.html.write(u'<li>%s</li>\n' % comic.name)
<ul> self.html.write(u'<ul>\n')
''' % comic)
def end(self): def end(self):
"""End HTML output.""" """End HTML output."""