summaryrefslogtreecommitdiff
path: root/imdb-lookup/imdbinfo.py
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2014-11-22 22:50:12 +0100
committerYves Fischer <yvesf-git@xapek.org>2014-11-22 22:50:12 +0100
commit85ed124b5d9a189d2eceb512c545f57b29e428de (patch)
treed85264a515a9f8fc31c1928d02645c06ddd5e0e5 /imdb-lookup/imdbinfo.py
parentc08d2b4a03f89c6fe5384474febb2e2f93a25ee2 (diff)
downloadscripts-85ed124b5d9a189d2eceb512c545f57b29e428de.tar.gz
scripts-85ed124b5d9a189d2eceb512c545f57b29e428de.zip
links to movies sites
Diffstat (limited to 'imdb-lookup/imdbinfo.py')
-rwxr-xr-ximdb-lookup/imdbinfo.py30
1 files changed, 18 insertions, 12 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',