From 17eaba3e2a17b019248e7f531b549477d92603b9 Mon Sep 17 00:00:00 2001 From: Kris Kater Date: Wed, 9 Jan 2013 22:37:38 +0100 Subject: [PATCH] Added rottentomatoes automation --- .../automation/rottentomatoes_com/__init__.py | 28 +++++++++ .../automation/rottentomatoes_com/main.py | 58 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 couchpotato/core/providers/automation/rottentomatoes_com/__init__.py create mode 100644 couchpotato/core/providers/automation/rottentomatoes_com/main.py diff --git a/couchpotato/core/providers/automation/rottentomatoes_com/__init__.py b/couchpotato/core/providers/automation/rottentomatoes_com/__init__.py new file mode 100644 index 00000000..92ff7870 --- /dev/null +++ b/couchpotato/core/providers/automation/rottentomatoes_com/__init__.py @@ -0,0 +1,28 @@ +from .main import Rottentomatoes + +def start(): + return Rottentomatoes() + +config = [{ + 'name': 'rottentomatoes', + 'groups': [ + { + 'tab': 'automation', + 'name': 'rottentomatoes_automation', + 'label': 'Rottentomatoes', + 'description': 'Imports movies from the rottentomatoes in theaters rss feed.', + 'options': [ + { + 'name': 'automation_enabled', + 'default': False, + 'type': 'enabler', + }, + { + 'name': 'tomatometer_percent', + 'default': '80', + 'label': 'Tomatometer' + } + ], + }, + ], +}] diff --git a/couchpotato/core/providers/automation/rottentomatoes_com/main.py b/couchpotato/core/providers/automation/rottentomatoes_com/main.py new file mode 100644 index 00000000..302056d5 --- /dev/null +++ b/couchpotato/core/providers/automation/rottentomatoes_com/main.py @@ -0,0 +1,58 @@ +from couchpotato.core.helpers.rss import RSS +from couchpotato.core.helpers.variable import md5 +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.automation.base import Automation +from xml.etree.ElementTree import QName +import datetime +import xml.etree.ElementTree as XMLTree +import re + +log = CPLog(__name__) + +class Rottentomatoes(Automation, RSS): + + interval = 1800 + rss_url = 'http://www.rottentomatoes.com/syndication/rss/in_theaters.xml' + + def getIMDBids(self): + + if self.isDisabled(): + return + + movies = [] + + cache_key = 'rottentomatoes.%s' % md5(self.rss_url) + rss_data = self.getCache(cache_key, self.rss_url) + data = XMLTree.fromstring(rss_data) + + if data: + + namespace = 'http://www.rottentomatoes.com/xmlns/rtmovie/' + rating_tag = str(QName(namespace, 'tomatometer_percent')) + rss_movies = self.getElements(data, 'channel/item') + + for movie in rss_movies: + + value = self.getTextElement(movie, "title") + result = re.search('(?<=%\s).*', value) + + if result: + + log.info('Something smells...') + rating = int(self.getTextElement(movie, rating_tag)) + name = result.group(0) + + if rating < int(self.conf('tomatometer_percent')): + + log.info('%s seems to be rotten...' % name) + + else: + + log.info('You find %s fresh enough though, enqueuing: %s' % (rating, name)) + year = datetime.datetime.now().strftime("%Y") + imdb = self.search(name, year) + + if imdb: + movies.append(imdb['imdb']) + + return movies