diff options
author | Thomas Keck <thomas@thinkpad> | 2014-11-15 21:57:19 +0100 |
---|---|---|
committer | Thomas Keck <thomas@thinkpad> | 2014-11-15 21:57:19 +0100 |
commit | d1f3ace287534f3d713c80d516d934432e8ae845 (patch) | |
tree | e9e36e6cdec794fff576dc1694e56f36c8b7504f /imdb-lookup | |
parent | 7de2d0f788cd13e77f5855286c96982f49a22690 (diff) | |
download | scripts-d1f3ace287534f3d713c80d516d934432e8ae845.tar.gz scripts-d1f3ace287534f3d713c80d516d934432e8ae845.zip |
Added support for multiple filenames
Diffstat (limited to 'imdb-lookup')
-rwxr-xr-x | imdb-lookup/imdbrating.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/imdb-lookup/imdbrating.py b/imdb-lookup/imdbrating.py index 995324c..dc2cd64 100755 --- a/imdb-lookup/imdbrating.py +++ b/imdb-lookup/imdbrating.py @@ -28,14 +28,18 @@ def read_key(): def get_rating(imdb_id): - return tmdb.Find(id=imdb_id).info(external_source="imdb_id")['movie_results'][0]['vote_average'] + info = tmdb.Find(id=imdb_id).info(external_source="imdb_id") + if 'movie_results' in info and len(info['movie_results']) == 1 and 'vote_average' in info['movie_results'][0]: + return info['movie_results'][0]['vote_average'] + return 0 if __name__ == u"__main__": tmdb.API_KEY = read_key() - imdb_id = sys.argv[1] - db = dbm.open('cache', 'rw') - if imdb_id not in db.keys(): - db[imdb_id] = str(get_rating(imdb_id)) - print db[imdb_id] + + for filename in sys.argv[1:]: + imdb_id = filename.split('#')[-1] + if imdb_id not in db.keys(): + db[imdb_id] = str(get_rating(imdb_id)) + print db[imdb_id] db.close() |