From 578e4c5a98c7178431e2ff641203c81882a4a444 Mon Sep 17 00:00:00 2001 From: Thomas Keck Date: Sat, 15 Nov 2014 23:21:07 +0100 Subject: dateiname als parameter --- imdb-lookup/imdbrating.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'imdb-lookup/imdbrating.py') diff --git a/imdb-lookup/imdbrating.py b/imdb-lookup/imdbrating.py index 662b8d9..ff0550b 100755 --- a/imdb-lookup/imdbrating.py +++ b/imdb-lookup/imdbrating.py @@ -39,13 +39,22 @@ def get_rating(imdb_id): return info['movie_results'][0]['vote_average'] return 0 +def print_ratings(files, db): + for filename in files: + if os.path.basename(filename).startswith('.'): + continue + elif os.path.isdir(filename): + print_ratings(map(lambda p: os.path.join(filename, p), os.listdir(filename)), db) + imdb_id = os.path.basename(filename).split('#')[-1] + if imdb_id.startswith('tt'): + if imdb_id not in db.keys() or db[imdb_id] == 0: + db[imdb_id] = str(get_rating(imdb_id)) + print u"{rating} {filename}".format(rating=db[imdb_id], filename=filename.decode('utf-8')) + if __name__ == u"__main__": tmdb.API_KEY = read_key() db = dbm.open(get_db_filename(), 'rw') - - for filename in sys.argv[1:]: - imdb_id = filename.split('#')[-1] - if imdb_id not in db.keys() or db[imdb_id] == 0: - db[imdb_id] = str(get_rating(imdb_id)) - print u"{rating} {filename}".format(rating=db[imdb_id], filename=filename.decode('utf-8')) + files = sum([os.listdir(x) if os.path.isdir(x) else [x] for x in sys.argv[1:]],[]) + print_ratings(files, db) db.close() + -- cgit v1.2.1