From 69cf46fa1816177e9d5731e7a03c9c3e8ba89d26 Mon Sep 17 00:00:00 2001 From: "davidaghaian@student.cccd.edu" Date: Sat, 4 Aug 2018 13:58:37 -0700 Subject: [PATCH] Added helper methods for obtaining movie ratings from rotten tomates --- helpers/rating.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 helpers/rating.py diff --git a/helpers/rating.py b/helpers/rating.py new file mode 100644 index 0000000..fd42d3a --- /dev/null +++ b/helpers/rating.py @@ -0,0 +1,18 @@ +from misc.log import logger +import json +import requests + +log = logger.get_logger(__name__) +def get_rating(apikey,imdbID): + log.debug("Requesting ratings from omdb for imdbID: %s",imdbID) + r = requests.get('http://www.omdbapi.com/?i=' + imdbID + '&apikey=' + apikey) + if(r.status_code == 200): + log.debug("Successfully requested ratings from OMDB") + for source in json.loads(r.text)["Ratings"]: + if(source['Source'] == 'Rotten Tomatoes'): + log.debug("Rotten Tomatoes shows rating: %s for imdbID: %s",source['Value'],imdbID) + return int(source['Value'].split('%')[0]) + else: + log.error("ERROR encountered while requesting rating for imdbID: %s Status Code: %d",imdbID,r.status_code) + + return -1