From c08d2b4a03f89c6fe5384474febb2e2f93a25ee2 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sat, 22 Nov 2014 20:54:32 +0100 Subject: css --- imdb-lookup/imdbinfo.py | 12 ++++-- imdb-lookup/index.jinja2.html | 93 ++++++++++++++++++++++++++----------------- 2 files changed, 66 insertions(+), 39 deletions(-) diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py index 71fd5f7..7b23356 100755 --- a/imdb-lookup/imdbinfo.py +++ b/imdb-lookup/imdbinfo.py @@ -10,12 +10,14 @@ import base64 import argparse import math import logging +from StringIO import StringIO try: from urllib.parse import quote as urlencode except: from urllib import quote as urlencode try: + from PIL import Image import tmdbsimple as tmdb import requests except ImportError as e: @@ -104,8 +106,11 @@ class TMDBCache(object): p = self.poster(poster_path, format) if not p: return None contentType, data = p + image = Image.open(StringIO(data)) + buf = StringIO() + image.save(buf, "JPEG", quality=10, optimize=True) data64 = "".join(map(lambda c: isinstance(c,int) and chr(c) or c, - filter(lambda c: c!='\n', base64.encodestring(data)))) + filter(lambda c: c!='\n', base64.encodestring(buf.getvalue())))) return "data:{};base64,{}".format(contentType, data64) @@ -119,7 +124,8 @@ class Protector(object): return attr(*a,**kw) except KeyboardInterrupt as e: raise e - except: + except Exception as e: + logging.error("Error calling %s: %s", name, e) return None if callable(attr): return protected @@ -191,7 +197,7 @@ def do_index(args, imdb_ids): outfile = open("index.html", "wb") for output in stream: output = output.encode("utf-8") - outfile.write(output) + outfile.write(output.strip()) class HelpAction(argparse._HelpAction): def __call__(self, parser, namespace, values, option_string=None): diff --git a/imdb-lookup/index.jinja2.html b/imdb-lookup/index.jinja2.html index a87092e..019e937 100644 --- a/imdb-lookup/index.jinja2.html +++ b/imdb-lookup/index.jinja2.html @@ -5,51 +5,72 @@ {{title}} + -

List of Movies

{% for (filename, imdb_id) in input %} {% set info = tmdbcache.infos(imdb_id) %} {% set posterBase64 = tmdbcache.poster_base64(info['poster_path']) %} {% if info %} -
-

- {% if "vote_average" in info.keys() %} - {{ " ".join(["★"] * int(info["vote_average"])) }} - - {{ " ".join(["☆"] * (10-int(info["vote_average"]))) }} - - {% endif %} - {{ info.title }} -

-
- {% if posterBase64 %} - - - - {% else %} - no image - {% endif %} -
-
-
- {{ info.overview }} -
- - {% for (key, value) in info.items() %} - {% if key in ['runtime','adult','homepage','release_date','original_title'] %} - - - - +
+
{{ key }}{{ value }}
+ + {% if "vote_average" in info.keys() %} + {% endif %} - {% endfor %} -
+ {{ " ".join(["☆"] * (10-int(info["vote_average"]))) }} + {{ " ".join(["★"] * int(info["vote_average"])) }} +
-
+ + {% if posterBase64 %} + + {% else %} + no image + {% endif %} + + +
{{ info.title }}
+
{{ info.overview }}
+ + {% for (key, value) in info.items() %} + {% if key in ['runtime','adult','homepage','release_date','original_title'] %} + + + + + {% endif %} + {% endfor %} +
{{ key }}{{ value }}
+ + +
- {% else %} + {% else %} No infos for {{filename}} {{imdb_id}} - {% endif %} + {% endif %} {% endfor %} -- cgit v1.2.1