summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-ximdb-lookup/imdbrating.py10
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]