summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-10-15 13:21:05 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-10-15 13:21:05 +0200
commitb4ed27646aedf17d1af314b32127d645eacd2a71 (patch)
tree28bf124a567b9e1c6d920b5e3ce278896c92fefe
parentd227826aef47c1ce8917a5139573c1063c540915 (diff)
mahou_showtime: Parse 'currenly airing' table from main page.
-rw-r--r--modules/mahou_showtime.py18
1 files changed, 10 insertions, 8 deletions
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.'