Advertisement
Atheuz

Untitled

May 10th, 2011
230
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. -@hook.command('rt')
  16. -def rottentomatoes(inp, bot=None):
  17. -    '.rt <title> -- gets ratings for <title> from Rotten Tomatoes'
  18. -
  19. -    api_key = bot.config.get("api_keys", {}).get("rottentomatoes", None)
  20. -    if not api_key:
  21. -        return None
  22. -
  23. -    title = inp.strip()
  24. -
  25. -    results = http.get_json(movie_search_url % (http.quote_plus(title), api_key))
  26. -    if results['total'] > 0:
  27. -        movie = results['movies'][0]
  28. -        title = movie['title']
  29. -        id = movie['id']
  30. -        critics_score = movie['ratings']['critics_score']
  31. -        audience_score = movie['ratings']['audience_score']
  32. -        url = movie['links']['alternate']
  33. -
  34. -        if critics_score != -1:
  35. -            reviews = http.get_json(movie_reviews_url%(id, api_key))
  36. -            review_count = reviews['total']
  37. -
  38. -            fresh = critics_score * review_count / 100
  39. -            rotten = review_count - fresh
  40. -
  41. +from util import http, hook
  42. +
  43. +api_root = 'http://api.rottentomatoes.com/api/public/v1.0/'
  44. +movie_search_url = api_root+'movies.json?q=%s&apikey=%s'
  45. +movie_info_url = api_root+'movies/%s.json?apikey=%s'
  46. +movie_reviews_url = api_root+'movies/%s/reviews.json?apikey=%s&review_type=all'
  47. +
  48. +response = u"%s - critics: \x02%d%%\x02 (%d\u2191%d\u2193) audience: \x02%d%%\x02 - %s"
  49. +
  50. +@hook.command('rt')
  51. +def rottentomatoes(inp, bot=None):
  52. +    '.rt <title> -- gets ratings for <title> from Rotten Tomatoes'
  53. +
  54. +    api_key = bot.config.get("api_keys", {}).get("rottentomatoes", None)
  55. +    if not api_key:
  56. +        return None
  57. +
  58. +    title = inp.strip()
  59. +
  60. +    results = http.get_json(movie_search_url % (http.quote_plus(title), api_key))
  61. +    if results['total'] > 0:
  62. +        movie = results['movies'][0]
  63. +        title = movie['title']
  64. +        id = movie['id']
  65. +        critics_score = movie['ratings']['critics_score']
  66. +        audience_score = movie['ratings']['audience_score']
  67. +        url = movie['links']['alternate']
  68. +
  69. +        if critics_score != -1:
  70. +            reviews = http.get_json(movie_reviews_url%(id, api_key))
  71. +            review_count = reviews['total']
  72. +
  73. +            fresh = critics_score * review_count / 100
  74. +            rotten = review_count - fresh
  75. +
  76.              return response % (title, critics_score, fresh, rotten, audience_score, url)
  77. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement