From b4ed27646aedf17d1af314b32127d645eacd2a71 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 15 Oct 2010 13:21:05 +0200 Subject: mahou_showtime: Parse 'currenly airing' table from main page. --- modules/mahou_showtime.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'modules') diff --git a/modules/mahou_showtime.py b/modules/mahou_showtime.py index 7e3dba6..60bae97 100644 --- a/modules/mahou_showtime.py +++ b/modules/mahou_showtime.py @@ -20,22 +20,24 @@ class Module: search = [x.lower() for x in search.split()] try: - if time.time() - self.lastcache >= 3600 or not self.cache: - self.cache = urllib2.urlopen('http://www.mahou.org/Showtime/Showtime.html').read() + if time.time() - self.lastcache >= 60 or not self.cache: + self.cache = urllib2.urlopen('http://www.mahou.org/Showtime/').read() self.lastcache = time.time() except: return 'Failed to fetch showtime data.' soup = BeautifulSoup(self.cache) - trs = soup.findAll('tr') + t = soup.find('table', attrs = {'summary': 'Currently Airing'}) + trs = t.tr.td.table.findAll('tr') del trs[0] # delete the "header" table row - # Note: 4th tr contains a hr - for tr1, tr2, tr3 in zip(trs[::4], trs[1::4], trs[2::4]): - title = tr1.td.b.a.text + for tr in trs: + tds = tr.findAll('td') + title = tds[1].text if all([x in title.lower() for x in search]): - eta, channel = [x.strip() for x in tr2('td')[1].text.split('/')] - airtime = tr3('td')[1].text + channel = tds[3].text + airtime = tds[5].text + eta = tds[6].text return '%s airs on %s at %s (eta: %s)' % (title, channel, airtime, eta) return 'No match found.' -- cgit v1.2.3