summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2014-11-22 17:04:33 +0100
committerYves Fischer <yvesf-git@xapek.org>2014-11-22 17:04:33 +0100
commitb81bbd0718e7a5b9cd50a3b7465dd9a1b6c523cb (patch)
treea9a7f489a759f938d981df74931d88daefc02f6c
parent377a4dd4ae8563a6882858dd6c4e1063d039f400 (diff)
downloadscripts-b81bbd0718e7a5b9cd50a3b7465dd9a1b6c523cb.tar.gz
scripts-b81bbd0718e7a5b9cd50a3b7465dd9a1b6c523cb.zip
logging
-rwxr-xr-ximdb-lookup/imdbinfo.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py
index 54c4816..70d2790 100755
--- a/imdb-lookup/imdbinfo.py
+++ b/imdb-lookup/imdbinfo.py
@@ -9,6 +9,7 @@ import json
import base64
import argparse
import math
+import logging
try:
import tmdbsimple as tmdb
@@ -50,12 +51,14 @@ class TMDBCache(object):
def _cache(self, key, callable_func):
if key not in self.db:
+ logging.info("Load value for key %s", key)
self.db[key] = json.dumps(callable_func())
d = self.db[key].decode('utf-8')
return json.loads(d)
def infos(self, movie_id):
try:
+ logging.debug("movie %s", movie_id)
return self._cache(movie_id + "movies.info", tmdb.Movies(movie_id).info)
except Exception as e:
raise Exception("Failed to query movie with id {id}: {reason}".format(id=movie_id, reason=str(e)))
@@ -81,10 +84,12 @@ class TMDBCache(object):
del self.db[key]
def poster(self, poster_path, format="w185"):
+ logging.debug("poster %s", poster_path)
key = "poster_{}_{}".format(format, poster_path)
keyContentType = "poster_{}_{}_content_type".format(format, poster_path)
url = "http://image.tmdb.org/t/p/{}/{}".format(format, poster_path)
if key not in self.db_images:
+ logging.info("Load poster %s", url)
r = requests.get(url)
self.db_images[key] = r.content
self.db_images[keyContentType] = r.headers['content-type']
@@ -211,6 +216,8 @@ if __name__ == u"__main__":
parser = argparse.ArgumentParser(description="get movie data", add_help=False)
parser.add_argument("--help", action=HelpAction, help="Display full help")
+ parser.add_argument("--log-level", action='store', type=int,
+ help="Set log level (CRITICAL=50,ERROR=40,WARNING=30,INFO=20,DEBUG=10,NOTSET=0")
parser.add_argument("-h", action=argparse._HelpAction, help="Display short help")
subparsers = parser.add_subparsers()
@@ -240,6 +247,8 @@ if __name__ == u"__main__":
parser_index.add_argument("files", action="append", nargs="+", help="Files containing distinct movie-ids")
args = parser.parse_args(sys.argv[1:])
+ if "log_level" in args:
+ logging.basicConfig(level=args.log_level)
ids = map(lambda filename: (lambda x: (filename, x.groups()[0]) if x else None)(re.match(".*#(tt[0-9]{7}).*", filename)),
args.files[0])