Advertisement
Atheuz

Untitled

May 10th, 2011
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.85 KB | None | 0 0
  1. diff --git a/plugins/rottentomatoes.py b/plugins/rottentomatoes.py
  2. index 5e20c43..46e1f75 100644
  3. --- a/plugins/rottentomatoes.py
  4. +++ b/plugins/rottentomatoes.py
  5. @@ -1,36 +1,36 @@
  6. -from util import http, hook
  7. -
  8. -api_root = 'http://api.rottentomatoes.com/api/public/v1.0/'
  9. -movie_search_url = api_root+'movies.json?q=%s&apikey=%s'
  10. -movie_info_url = api_root+'movies/%s.json?apikey=%s'
  11. -movie_reviews_url = api_root+'movies/%s/reviews.json?apikey=%s&review_type=all'
  12. -
  13. -response = u"%s - critics: \x02%d%%\x02 (%d\u2191%d\u2193) audience: \x02%d%%\x02 - %s"
  14. -
  15. -def rottentomatoes(inp, bot=None):
  16. -    '.rt <title> -- gets ratings for <title> from Rotten Tomatoes'
  17. -
  18. -    api_key = bot.config.get("api_keys", {}).get("rottentomatoes", None)
  19. -    if not api_key:
  20. -        return None
  21. -
  22. -    title = inp.strip()
  23. -
  24. -    results = http.get_json(movie_search_url % (http.quote_plus(title), api_key))
  25. -    if results['total'] > 0:
  26. -        movie = results['movies'][0]
  27. -        title = movie['title']
  28. -        id = movie['id']
  29. -        critics_score = movie['ratings']['critics_score']
  30. -        audience_score = movie['ratings']['audience_score']
  31. -        url = movie['links']['alternate']
  32. -
  33. -        if critics_score != -1:
  34. -            reviews = http.get_json(movie_reviews_url%(id, api_key))
  35. -            review_count = reviews['total']
  36. -
  37. -            fresh = critics_score * review_count / 100
  38. -            rotten = review_count - fresh
  39. -
  40. +from util import http, hook
  41. +
  42. +api_root = 'http://api.rottentomatoes.com/api/public/v1.0/'
  43. +movie_search_url = api_root+'movies.json?q=%s&apikey=%s'
  44. +movie_info_url = api_root+'movies/%s.json?apikey=%s'
  45. +movie_reviews_url = api_root+'movies/%s/reviews.json?apikey=%s&review_type=all'
  46. +
  47. +response = u"%s - critics: \x02%d%%\x02 (%d\u2191%d\u2193) audience: \x02%d%%\x02 - %s"
  48. +
  49. +def rottentomatoes(inp, bot=None):
  50. +    '.rt <title> -- gets ratings for <title> from Rotten Tomatoes'
  51. +
  52. +    api_key = bot.config.get("api_keys", {}).get("rottentomatoes", None)
  53. +    if not api_key:
  54. +        return None
  55. +
  56. +    title = inp.strip()
  57. +
  58. +    results = http.get_json(movie_search_url % (http.quote_plus(title), api_key))
  59. +    if results['total'] > 0:
  60. +        movie = results['movies'][0]
  61. +        title = movie['title']
  62. +        id = movie['id']
  63. +        critics_score = movie['ratings']['critics_score']
  64. +        audience_score = movie['ratings']['audience_score']
  65. +        url = movie['links']['alternate']
  66. +
  67. +        if critics_score != -1:
  68. +            reviews = http.get_json(movie_reviews_url%(id, api_key))
  69. +            review_count = reviews['total']
  70. +
  71. +            fresh = critics_score * review_count / 100
  72. +            rotten = review_count - fresh
  73. +
  74.              return response % (title, critics_score, fresh, rotten, audience_score, url)
  75. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement