summaryrefslogtreecommitdiff
path: root/modules/mahou_showtime.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-06-09 01:08:40 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-06-09 01:08:40 +0200
commit7cec7c641da41c3c456fcaab07046b84d49566ef (patch)
treef2c916e800d3fbb5de6a248825f203c5d2bda426 /modules/mahou_showtime.py
parent7e5d0416c10a123cdfce1e0c669284fe61d57b8b (diff)
modules: Added mahou Showtime! parser for listing anime airings.
Diffstat (limited to 'modules/mahou_showtime.py')
-rw-r--r--modules/mahou_showtime.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/modules/mahou_showtime.py b/modules/mahou_showtime.py
new file mode 100644
index 0000000..ee4e387
--- /dev/null
+++ b/modules/mahou_showtime.py
@@ -0,0 +1,52 @@
+info = {
+ 'author': 'Jon Bergli Heier',
+ 'title': 'mahou Showtime',
+ 'description': 'Parser for "mahou Showtime!"',
+}
+
+import urllib2, time
+from BeautifulSoup import BeautifulSoup
+
+class Module:
+ def __init__(self, bot):
+ self.irc = bot
+ if self.irc:
+ self.irc.register_keyword('!ep', self)
+
+ self.cache = ''
+ self.lastcache = 0
+
+ def find_next(self, search):
+ 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()
+ self.lastcache = time.time()
+ except:
+ return 'Failed to fetch showtime data.'
+ soup = BeautifulSoup(self.cache)
+
+ trs = soup.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
+ 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
+ return '%s airs on %s at %s (eta: %s)' % (title, channel, airtime, eta)
+ return 'No match found.'
+
+ def keyword(self, nick, channel, kw, msg):
+ target = channel if not channel == self.irc.nickname else nick.split('!')[0]
+ args = msg.split()
+ if len(args) == 0:
+ self.irc.msg(target, 'Usage: !ep search')
+ return
+
+if __name__ == '__main__':
+ import sys
+ m = Module(None)
+ print m.find_next(' '.join(sys.argv[1:]))