From a6ff2d8166723026b3db0092399fe6f694fa0750 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Mon, 8 Dec 2014 23:49:07 +0100 Subject: more data! --- imdb-lookup/imdbinfo.py | 12 +++++++ imdb-lookup/index.jinja2.html | 83 +++++++++++++++++++++++++++++++------------ 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py index 5c88fc1..eeea947 100755 --- a/imdb-lookup/imdbinfo.py +++ b/imdb-lookup/imdbinfo.py @@ -167,6 +167,18 @@ class TMDBCache(object): key = "imdb_maindetails_{}".format(movie_id) return self._cache(key, do_request) + def omdb_movie(self, movie_id): + def do_request(): + BASE_URI="http://www.omdbapi.com/" + params={'i':movie_id, 'plot':'short', 'r':'json', 'tomatoes':'true'} + r = requests.get(BASE_URI, params=params) + assert r.status_code == 200, "Request must return status-code 200" + data = json.loads(r.text) + assert data is not None and data['Response'] == 'True', "Data must not be empty" + return data + key = "omdb_{}".format(movie_id) + return self._cache(key, do_request) + def weight_rating(infos): """ add 'rating' to all infos""" diff --git a/imdb-lookup/index.jinja2.html b/imdb-lookup/index.jinja2.html index 21c263f..a3cf411 100644 --- a/imdb-lookup/index.jinja2.html +++ b/imdb-lookup/index.jinja2.html @@ -18,16 +18,17 @@ background-color: #EFAAAA; height: 150px; } - .td1, .td2, .td3, .td4 { + .td1, .td2, .td3, .td4, .td5 { width: 1em; font-size: 18pt; - padding: 5px; + padding: 2px; vertical-align: top; } .td1 .on { color: #ffd700; } .td2 .on { color: blue; } - .td1, .td2 .off { color: gray; } - .td1 .num, .td2 .num { font-size: 12pt; color: gray; } + .td3 .on { color: red; } + .td4 .on { color: black; } + .td1 .off, .td2 .off, .td3 .off, .td4 .off, .td5 .off{ color: #c0c0c0; } .poster { margin: 10px; width: 185px; @@ -40,11 +41,19 @@ vertical-align: top; } .info table td { padding: .2em; } - .details { padding: 1em; } + .details { padding: 0.5em; } .files { list-style: none; padding-left: 0px; - font-size: 0.9em; + font-size: 0.7em; + margin: 0px; + } + .imdbid { + font-family: monospace; + padding: 3px; + background-color: #f0f0f0; + border: 1px solid #e0e0e0; + border-radius: 4px; } .files li:before { margin: 0 1em; content: '▶'; } .headline { font-size: 0.9em; color: 3e3e3e; } @@ -56,39 +65,59 @@ color: #ccc; font-style: italic; } + .rated { + border: 1px solid black; + border-radius: 5px; + font-size:0.7em; + padding: 2px; + } {% for (path, imdb_id) in input %} {% set info = tmdbcache.infos(imdb_id) %} {% if info %} - {% set age = gmtime.tm_year - int(info['release_date'].split('-')[0]) %} + {% set year = int(info['release_date'].split('-')[0]) %} + {% set age = gmtime.tm_year - year %} {% set centuries = int(age / 10) %} {% set posterBase64 = tmdbcache.poster_base64(info['poster_path']) %} {% set local_title = tmdbcache.alternative_title(imdb_id, "DE") %} {% set imdb_data = tmdbcache.imdb_movie(imdb_id)['data'] %} + {% set omdb_data = tmdbcache.omdb_movie(imdb_id) %} {% set votes = imdb_data['num_votes'] %} {% set popularity = int( 9*(1 - (1+math.exp(-1))/(1+math.exp(votes/70000.0 -1 ))) + 1 ) %} + {% set fresh = (omdb_data.tomatoMeter != 'N/A') and int(omdb_data.tomatoMeter) or None %} + {% set userMeter = (omdb_data.tomatoUserMeter != 'N/A') and int(omdb_data.tomatoUserMeter) or None %}
{% if "vote_average" in info.keys() %} - - - + {% else %} + + {% endif %} + {% if fresh %} + + {% else %} + + {% endif %} + - {% endif %} @@ -109,7 +138,10 @@
by {{ imdb_data["directors_summary"] | join(", ", attribute="name.name") }}, - runtime {{ info['runtime'] }} min. + runtime {{ info['runtime'] }} min, {{year}} + {% if omdb_data.Rated != 'N/A' %} + {{omdb_data.Rated}} + {% endif %}
Starring: {{ imdb_data["cast_summary"] | join(", ", attribute="name.name") }} @@ -119,14 +151,17 @@
- {{ " ".join(["☆"] * (10-int(info["vote_average"]))) }} - {{ " ".join(["★"] * int(info["vote_average"])) }} - {{info["vote_average"]}} - + {{ " ".join(["☆"] * (10-int(imdb_data["rating"]))) }} {{ " ".join(["★"] * int(imdb_data["rating"])) }} - {{imdb_data["rating"]}} + {% if userMeter %} + + {{ " ".join(["☆"] * (10-int(userMeter/10))) }} + {{ " ".join(["★"] * int(userMeter/10)) }} + + {{ " ".join(["☆"] * (10-int(fresh/10))) }} + {{ " ".join(["★"] * int(fresh/10)) }} + {{ " ".join(["☆"] * (10-popularity)) }} {{ " ".join(["★"] * popularity) }} - {{ " ".join(["  "] * (9-centuries)) }} + + {{ " ".join(["⌚"] * (9-centuries)) }} {{ " ".join(["⌚"] * (centuries + 1)) }}
{% if 'homepage' in info and info['homepage'] %} - - + - {% endif %} + {% elif omdb_data.Website != "N/A" %} - - + + {% endif %}
Homepage{{ info['homepage'] }} + ➜ {{ info['homepage'] }} +
Release{{ info['release_date'] }} {% if age > 0 %}  ({{ age }} year{% if age > 1 %}s{% endif %}   old){% endif %} + ➜ {{ omdb_data.Website }} +
themoviedb.org @@ -136,6 +171,8 @@ ➜ letterboxd.com   ➜ ofdb.db +   + ➜ {{ info.imdb_id }}
-- cgit v1.2.1