From 85ed124b5d9a189d2eceb512c545f57b29e428de Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sat, 22 Nov 2014 22:50:12 +0100 Subject: links to movies sites --- imdb-lookup/imdbinfo.py | 30 ++++--- imdb-lookup/index.jinja2.html | 189 ++++++++++++++++++++++++++---------------- 2 files changed, 136 insertions(+), 83 deletions(-) diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py index 7b23356..caf00a4 100755 --- a/imdb-lookup/imdbinfo.py +++ b/imdb-lookup/imdbinfo.py @@ -6,15 +6,16 @@ import sys import re import dbm import json +import time 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 StringIO import StringIO +except: from io import StringIO + +try: from urllib.parse import quote as urlencode +except: from urllib import quote as urlencode try: from PIL import Image @@ -112,7 +113,16 @@ class TMDBCache(object): data64 = "".join(map(lambda c: isinstance(c,int) and chr(c) or c, filter(lambda c: c!='\n', base64.encodestring(buf.getvalue())))) return "data:{};base64,{}".format(contentType, data64) - + + +def weight_rating(infos): + """ add 'rating' to all infos""" + maxvotes = max(map(lambda i: i["vote_count"], infos)) + for info in infos: + f = math.sin(math.pi * ( info["vote_average"]/10.0 ) ) + d = (float(info["vote_count"]) / maxvotes) - 0.5 + info['rating'] = info["vote_average"] + 2 * d * f + return infos class Protector(object): def __init__(self, child): @@ -161,11 +171,8 @@ def do_rating(args, imdb_ids): with TMDBCache() as tmdbcache: infos = list(filter(lambda i: "vote_average" in i and "vote_count" in i, map(lambda fid: tmdbcache.infos(fid[1]), imdb_ids))) - maxvotes = max(map(lambda i: i["vote_count"], infos)) + weight_rating(infos) for info in infos: - f = math.sin(math.pi * ( info["vote_average"]/10.0 ) ) - d = (float(info["vote_count"]) / maxvotes) - 0.5 - info['rating'] = info["vote_average"] + 2 * d * f print(u"{rating:.02f} {imdb_id} {title:30s} avg={vote_average:.1f} count={vote_count:.0f}".format(**info)) @@ -183,9 +190,8 @@ def do_index(args, imdb_ids): template_file = os.path.join(os.path.dirname(__file__), "index.jinja2.html") template = Template(open(template_file, "rb").read().decode('utf-8')) with TMDBCache() as tmdbcache: - #infos = list(map(tmdbcache.infos, imdb_ids)) - #posters = list(map(asBase64, map(tmdbcache.poster, map(lambda info: info['poster_path'], infos)))) mapping = { + 'gmtime' : time.gmtime(), 'input' : imdb_ids, 'tmdbcache' : Protector(tmdbcache), 'title' : 'Movie overview', diff --git a/imdb-lookup/index.jinja2.html b/imdb-lookup/index.jinja2.html index 019e937..b318b83 100644 --- a/imdb-lookup/index.jinja2.html +++ b/imdb-lookup/index.jinja2.html @@ -2,75 +2,122 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> - - - {{title}} - - - - {% 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() %} - - {% endif %} - - - -
- {{ " ".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 %} - No infos for {{filename}} {{imdb_id}} - {% endif %} - {% endfor %} - + + + {{title}} + + + + {% for (filename, imdb_id) in input %} + {% set info = tmdbcache.infos(imdb_id) %} + {% if info %} + {% set age = gmtime.tm_year - int(info['release_date'].split('-')[0]) %} + {% set centuries = int(age / 10) %} + {% set posterBase64 = tmdbcache.poster_base64(info['poster_path']) %} +
+ + + {% if "vote_average" in info.keys() %} + + + + {% endif %} + + + +
+ {{ " ".join(["☆"] * (10-int(info["vote_average"]))) }} + {{ " ".join(["★"] * int(info["vote_average"])) }} + + {{ " ".join(["☆"] * (10-int(info["popularity"]*10))) }} + {{ " ".join(["★"] * int(info["popularity"]*10)) }} + + {{ " ".join(["  "] * (10-centuries)) }} + {{ " ".join(["⌚"] * centuries) }} + + {% if posterBase64 %} + + {% else %} + no image + {% endif %} + +
+ {{ info.title }} + {% if info.title != info.original_title %} +  ({{ info.original_title }}) + {% endif %} +
+
{{ info.overview }}
+ + {% if 'runtime' in info %} + + + + + {% endif %} + {% if 'homepage' in info %} + + + + + {% endif %} + + + + + + + +
Runtime{{ info['runtime'] }}
Homepage{{ info['homepage'] }}
Release{{ info['release_date'] }} {% if age > 0 %}  ({{ age }} year{% if age > 1 %}s{% endif %}   old){% endif %}
+ → themoviedb.org +   + → imdb.com +   + → letterboxd.com +   + → ofdb.db +
+
+
+ {% else %} +
+ No infos for {{filename}} {{imdb_id}} +
+ {% endif %} + {% endfor %} + + -- cgit v1.2.1