cleanup rottentomatoes
This commit is contained in:
parent
f42b8ec280
commit
92c6e991e7
|
@ -1,37 +1,39 @@
|
||||||
from util import http, hook
|
from util import http, hook
|
||||||
|
|
||||||
api_root = 'http://api.rottentomatoes.com/api/public/v1.0/'
|
api_root = 'http://api.rottentomatoes.com/api/public/v1.0/'
|
||||||
movie_search_url = api_root+'movies.json?q=%s&apikey=%s'
|
movie_search_url = api_root + 'movies.json'
|
||||||
movie_info_url = api_root+'movies/%s.json?apikey=%s'
|
movie_reviews_url = api_root + 'movies/%s/reviews.json'
|
||||||
movie_reviews_url = api_root+'movies/%s/reviews.json?apikey=%s&review_type=all'
|
|
||||||
|
|
||||||
response = u"%s - critics: \x02%d%%\x02 (%d\u2191%d\u2193) audience: \x02%d%%\x02 - %s"
|
@hook.command('rt')
|
||||||
|
def rottentomatoes(inp, bot=None):
|
||||||
|
'.rt <title> -- gets ratings for <title> from Rotten Tomatoes'
|
||||||
@hook.command('rt')
|
|
||||||
def rottentomatoes(inp, bot=None):
|
api_key = bot.config.get("api_keys", {}).get("rottentomatoes", None)
|
||||||
'.rt <title> -- gets ratings for <title> from Rotten Tomatoes'
|
if not api_key:
|
||||||
|
return
|
||||||
api_key = bot.config.get("api_keys", {}).get("rottentomatoes", None)
|
|
||||||
if not api_key:
|
title = inp.strip()
|
||||||
return None
|
|
||||||
|
results = http.get_json(movie_search_url, q=title, apikey=api_key)
|
||||||
title = inp.strip()
|
if results['total'] == 0:
|
||||||
|
return 'no results'
|
||||||
results = http.get_json(movie_search_url % (http.quote_plus(title), api_key))
|
|
||||||
if results['total'] > 0:
|
movie = results['movies'][0]
|
||||||
movie = results['movies'][0]
|
title = movie['title']
|
||||||
title = movie['title']
|
id = movie['id']
|
||||||
id = movie['id']
|
critics_score = movie['ratings']['critics_score']
|
||||||
critics_score = movie['ratings']['critics_score']
|
audience_score = movie['ratings']['audience_score']
|
||||||
audience_score = movie['ratings']['audience_score']
|
url = movie['links']['alternate']
|
||||||
url = movie['links']['alternate']
|
|
||||||
|
if critics_score == -1:
|
||||||
if critics_score != -1:
|
return
|
||||||
reviews = http.get_json(movie_reviews_url%(id, api_key))
|
|
||||||
review_count = reviews['total']
|
reviews = http.get_json(movie_reviews_url % id, apikey=api_key, review_type='all')
|
||||||
|
review_count = reviews['total']
|
||||||
fresh = critics_score * review_count / 100
|
|
||||||
rotten = review_count - fresh
|
fresh = critics_score * review_count / 100
|
||||||
|
rotten = review_count - fresh
|
||||||
return response % (title, critics_score, fresh, rotten, audience_score, url)
|
|
||||||
|
return u"%s - critics: \x02%d%%\x02 (%d\u2191%d\u2193)" \
|
||||||
|
" audience: \x02%d%%\x02 - %s" % (title, critics_score, fresh, rotten, audience_score, url)
|
||||||
|
|
Loading…
Reference in New Issue