summaryrefslogtreecommitdiff
path: root/imdb-lookup/imdbinfo.py
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2014-11-16 23:03:08 +0100
committerYves Fischer <yvesf-git@xapek.org>2014-11-16 23:03:08 +0100
commit522517568d71d7ad0688422b64c48387aafee026 (patch)
tree53f9fb3c1b4c62c5a715f233d05ac4904da9b141 /imdb-lookup/imdbinfo.py
parent5de44c7724306dc4aabdd0161b7779a9462ef110 (diff)
downloadscripts-522517568d71d7ad0688422b64c48387aafee026.tar.gz
scripts-522517568d71d7ad0688422b64c48387aafee026.zip
rating subcommand
Diffstat (limited to 'imdb-lookup/imdbinfo.py')
-rwxr-xr-ximdb-lookup/imdbinfo.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py
index 37287bb..63daa21 100755
--- a/imdb-lookup/imdbinfo.py
+++ b/imdb-lookup/imdbinfo.py
@@ -98,6 +98,16 @@ def do_prune(args, imdb_ids):
for imdb_id in imdb_ids:
tmdbcache.prune(imdb_id)
+def do_rating(args, imdb_ids):
+ with TMDBCache() as tmdbcache:
+ infos = map(lambda imdb_id: tmdbcache.infos(imdb_id), imdb_ids)
+ infos = filter(lambda i: "vote_average" in i and "vote_count" in i, infos)
+ maxvotes = max(map(lambda i: i["vote_count"], infos))
+ minvotes = min(map(lambda i: i["vote_count"], infos))
+ for info in infos:
+ info['rating'] = info["vote_average"] + 2*((float(info["vote_count"])/maxvotes) - 0.5)
+ print "{rating:.02f} {imdb_id} {title:30s} avg={vote_average:.1f} count={vote_count:.0f}".format(**info)
+
if __name__ == u"__main__":
tmdb.API_KEY = read_key()
@@ -120,6 +130,10 @@ if __name__ == u"__main__":
parser_prune.set_defaults(func=do_prune)
parser_prune.add_argument("files", action="append", nargs="+")
+ parser_rating = subparsers.add_parser("rating")
+ parser_rating.set_defaults(func=do_rating)
+ parser_rating.add_argument("files", action="append", nargs="+")
+
args = parser.parse_args(sys.argv[1:])
ids = map(lambda filename: (lambda x: x.groups()[0] if x else None)(re.match(".*#(tt[0-9]{7}).*", filename)),