From 87ab025dfe883916820ecd51fd88974cabd3eb04 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sat, 15 Nov 2014 21:57:44 +0100 Subject: cache file --- imdb-lookup/imdbrating.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'imdb-lookup/imdbrating.py') diff --git a/imdb-lookup/imdbrating.py b/imdb-lookup/imdbrating.py index dc2cd64..de4c167 100755 --- a/imdb-lookup/imdbrating.py +++ b/imdb-lookup/imdbrating.py @@ -25,7 +25,13 @@ def read_key(): if os.path.exists(os.path.join(os.path.expanduser(u"~"), ".tmdbkey")): return open(os.path.join(os.path.expanduser(u"~"), ".tmdbkey")).read().strip() raise Exception(u"No TheMovieDB Key defined. Set Env. var. TMDB_KEY or .tmdbkey file") - + +def get_db_filename(): + if u"XDG_CACHE_HOME" in os.environ.keys(): + cachedir = os.environ["XDG_CACHE_HOME"] + else: + cachedir = os.path.join(os.path.expanduser(u"~"), ".cache") + return os.path.join(cachedir, "imdbrating.dbm") def get_rating(imdb_id): info = tmdb.Find(id=imdb_id).info(external_source="imdb_id") @@ -35,7 +41,7 @@ def get_rating(imdb_id): if __name__ == u"__main__": tmdb.API_KEY = read_key() - db = dbm.open('cache', 'rw') + db = dbm.open(get_db_filename(), 'rw') for filename in sys.argv[1:]: imdb_id = filename.split('#')[-1] -- cgit v1.2.1