phenny-1/modules/wuvt.py

40 lines
1.2 KiB
Python

#!/usr/bin/env python
"""
wuvt.py - Phenny WUVT Module
Copyright 2012, Randy Nance, randynance.info
http://github.com/randynobx/phenny/
"""
from tools import GrumbleError
import re
import web
re.MULTILINE
r_play = re.compile(r'^(.*?) - (.*?)$')
r_dj = re.compile(r'Current DJ: </span>\n(.+?)<')
def wuvt(phenny, input):
""".wuvt - Find out what is currently playing on the radio station WUVT."""
try:
playing = web.get('http://www.wuvt.vt.edu/playlists/latest_track.php')
djpage = web.get('http://www.wuvt.vt.edu/playlists/current_dj.php')
except:
raise GrumbleError('Cannot connect to wuvt')
play= r_play.search(playing)
song = play.group(2)
artist = play.group(1)
dj = r_dj.search(djpage).group(1)
if song and artist:
if dj[0:3] == 'DJ ':
phenny.reply('{0} is currently playing: {1} by {2}'
.format(dj.strip(), song.strip(), artist.strip()))
else:
phenny.reply('DJ {0} is currently playing: {1} by {2}'
.format(dj.strip(), song.strip(), artist.strip()))
else:
phenny.reply('Cannot connect to wuvt')
wuvt.commands = ['wuvt']