diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2014-11-15 21:57:44 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2014-11-15 21:58:43 +0100 |
commit | 87ab025dfe883916820ecd51fd88974cabd3eb04 (patch) | |
tree | 43ff3b9d7aa6e54ddb7f82e866782e523ebf22d3 /imdb-lookup/imdbrating.py | |
parent | d1f3ace287534f3d713c80d516d934432e8ae845 (diff) | |
download | scripts-87ab025dfe883916820ecd51fd88974cabd3eb04.tar.gz scripts-87ab025dfe883916820ecd51fd88974cabd3eb04.zip |
cache file
Diffstat (limited to 'imdb-lookup/imdbrating.py')
-rwxr-xr-x | imdb-lookup/imdbrating.py | 10 |
1 files changed, 8 insertions, 2 deletions
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] |