summaryrefslogtreecommitdiff
path: root/imdb-lookup/imdbinfo.py
diff options
context:
space:
mode:
Diffstat (limited to 'imdb-lookup/imdbinfo.py')
-rwxr-xr-ximdb-lookup/imdbinfo.py45
1 files changed, 22 insertions, 23 deletions
diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py
index 5c27ec7..504528a 100755
--- a/imdb-lookup/imdbinfo.py
+++ b/imdb-lookup/imdbinfo.py
@@ -1,8 +1,9 @@
#!/usr/bin/env python2
# coding: utf-8
# python3 works as well
-import os
import sys
+assert sys.version.startswith("3."), "Requires python3"
+import os
import re
import dbm
import json
@@ -12,33 +13,31 @@ import argparse
import math
import logging
import hashlib
-try: from StringIO import StringIO
-except: from io import StringIO
+from io import StringIO
-try: from urllib.parse import quote as urlencode
-except: from urllib import quote as urlencode
+from urllib.parse import quote as urlencode
try:
from PIL import Image
import tmdbsimple as tmdb
import requests
except ImportError as e:
- print(u"Missing dependency: {0}".format(str(e)))
- print(u"Install using system package manager or `pip install --user <module>`")
+ print("Missing dependency: {0}".format(str(e)))
+ print("Install using system package manager or `pip install --user (one of: Pillow tmdbsimple requests)`")
sys.exit(1)
def read_key():
- if u"TMDB_KEY" in os.environ.keys():
- return os.environ[u"TMDB_KEY"]
- if u"XDG_CONFIG_HOME" in os.environ.keys():
- cfg_home = os.environ[u"XDG_CONFIG_HOME"]
+ if "TMDB_KEY" in os.environ.keys():
+ return os.environ["TMDB_KEY"]
+ if "XDG_CONFIG_HOME" in os.environ.keys():
+ cfg_home = os.environ["XDG_CONFIG_HOME"]
else:
- cfg_home = os.path.join(os.path.expanduser(u"~"), ".config")
- if os.path.exists(os.path.join(cfg_home, u"tmdbkey")):
- return open(os.path.join(cfg_home, u"tmdbkey"), "r").read().strip()
- 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")
+ cfg_home = os.path.join(os.path.expanduser("~"), ".config")
+ if os.path.exists(os.path.join(cfg_home, "tmdbkey")):
+ return open(os.path.join(cfg_home, "tmdbkey"), "r").read().strip()
+ if os.path.exists(os.path.join(os.path.expanduser("~"), ".tmdbkey")):
+ return open(os.path.join(os.path.expanduser("~"), ".tmdbkey")).read().strip()
+ raise Exception("No TheMovieDB Key defined. Set Env. var. TMDB_KEY or .tmdbkey file")
class TMDBCache(object):
def __enter__(self):
@@ -54,10 +53,10 @@ class TMDBCache(object):
self.db_images.close()
def _get_db_filename(self, name):
- if u"XDG_CACHE_HOME" in os.environ.keys():
+ if "XDG_CACHE_HOME" in os.environ.keys():
cachedir = os.environ["XDG_CACHE_HOME"]
else:
- cachedir = os.path.join(os.path.expanduser(u"~"), ".cache")
+ cachedir = os.path.join(os.path.expanduser("~"), ".cache")
return os.path.join(cachedir, name)
def _cache(self, key, callable_func):
@@ -200,10 +199,10 @@ def do_data(args, imdb_ids):
with TMDBCache() as tmdbcache:
for (filename, imdb_id) in imdb_ids:
selected_properties = ["imdb_id", "revenue", "vote_average", "vote_count", "runtime", "budget", "vote_avarage", "release_date", "popularity", ]
- kv = map(lambda kv: u"{}={}".format(*kv),
+ kv = map(lambda kv: "{}={}".format(*kv),
filter(lambda kv: kv[0] in selected_properties,
tmdbcache.infos(imdb_id).items()))
- print(u" ".join(kv))
+ print(" ".join(kv))
def do_year(args, imdb_ids):
with TMDBCache() as tmdbcache:
@@ -222,7 +221,7 @@ def do_rating(args, imdb_ids):
map(lambda fid: tmdbcache.infos(fid[1]), imdb_ids)))
weight_rating(infos)
for info in infos:
- print(u"{rating:.02f} {imdb_id} {title:30s} avg={vote_average:.1f} count={vote_count:.0f}".format(**info))
+ print("{rating:.02f} {imdb_id} {title:30s} avg={vote_average:.1f} count={vote_count:.0f}".format(**info))
def do_index(args, imdb_ids):
@@ -296,7 +295,7 @@ def do_test(args):
import doctest
doctest.testmod()
-if __name__ == u"__main__":
+if __name__ == "__main__":
tmdb.API_KEY = read_key()
parser = argparse.ArgumentParser(description="get movie data", add_help=False)