From 522517568d71d7ad0688422b64c48387aafee026 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sun, 16 Nov 2014 23:03:08 +0100 Subject: rating subcommand --- imdb-lookup/imdbinfo.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'imdb-lookup/imdbinfo.py') 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)), -- cgit v1.2.1