Pass entire move object instead of just ID for logging purposes

pull/49/merge^2
davidaghaian@student.cccd.edu 6 years ago
parent 7ac88d4cb8
commit a906b361ec

@ -3,16 +3,24 @@ import json
import requests import requests
log = logger.get_logger(__name__) log = logger.get_logger(__name__)
def get_rating(apikey,imdbID): def get_rating(apikey,movie):
log.debug("Requesting ratings from omdb for imdbID: %s",imdbID) imdbID = movie['movie']['ids']['imdb']
log.debug("Requesting ratings from OMDB for %s (%d) | Genres: %s | Country: %s | imdbID: %s",movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(),imdbID)
r = requests.get('http://www.omdbapi.com/?i=' + imdbID + '&apikey=' + apikey) r = requests.get('http://www.omdbapi.com/?i=' + imdbID + '&apikey=' + apikey)
if(r.status_code == 200): if(r.status_code == 200):
log.debug("Successfully requested ratings from OMDB") log.debug("Successfully requested ratings from OMDB for %s (%d) | Genres: %s | Country: %s | imdbID: %s",
movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(), imdbID)
for source in json.loads(r.text)["Ratings"]: for source in json.loads(r.text)["Ratings"]:
if(source['Source'] == 'Rotten Tomatoes'): if(source['Source'] == 'Rotten Tomatoes'):
log.debug("Rotten Tomatoes shows rating: %s for imdbID: %s",source['Value'],imdbID) log.debug("Rotten Tomatoes shows rating: %s for %s (%d) | Genres: %s | Country: %s | imdbID: %s ",source['Value'],movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(),imdbID)
return int(source['Value'].split('%')[0]) return int(source['Value'].split('%')[0])
else: else:
log.error("ERROR encountered while requesting rating for imdbID: %s Status Code: %d",imdbID,r.status_code) log.debug("Error encountered when requesting ratings from OMDB for %s (%d) | Genres: %s | Country: %s | imdbID: %s",
movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(), imdbID)
return -1 return -1

@ -523,7 +523,7 @@ def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', rating=0, genre=
# Assuming the movie is not blacklisted, proceed to pull RT score if the user wishes to restrict # Assuming the movie is not blacklisted, proceed to pull RT score if the user wishes to restrict
movieRating = None movieRating = None
if (rating and cfg['omdb']['api_key'] != ''): if (rating and cfg['omdb']['api_key'] != ''):
movieRating = rating_helper.get_rating(cfg['omdb']['api_key'], movie['movie']['ids']['imdb']) movieRating = rating_helper.get_rating(cfg['omdb']['api_key'],movie)
if (movieRating == -1): if (movieRating == -1):
log.debug("Skipping: %s because it did not have a rating/lacked imdbID", log.debug("Skipping: %s because it did not have a rating/lacked imdbID",
movie['movie']['title']) movie['movie']['title'])

Loading…
Cancel
Save