update wuvt module for new site

master
mutantmonkey 2015-03-05 16:14:46 -08:00
parent 83b286e8af
commit d963ac2e70
2 changed files with 16 additions and 26 deletions

View File

@ -15,7 +15,7 @@ class TestWuvt(unittest.TestCase):
def test_wuvt(self): def test_wuvt(self):
wuvt(self.phenny, None) wuvt(self.phenny, None)
out = self.phenny.reply.call_args[0][0] out = self.phenny.say.call_args[0][0]
m = re.match('^DJ .* is currently playing: .* by .*$', out, m = re.match('^DJ .* is currently playing .* by .*$', out,
flags=re.UNICODE) flags=re.UNICODE)
self.assertTrue(m) self.assertTrue(m)

View File

@ -1,39 +1,29 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
wuvt.py - Phenny WUVT Module wuvt.py - WUVT now playing module for phenny
Copyright 2012, Randy Nance, randynance.info
http://github.com/randynobx/phenny/
""" """
from tools import GrumbleError from tools import GrumbleError
import re
import web import web
re.MULTILINE
r_play = re.compile(r'^(.*?) - (.*?)$')
r_dj = re.compile(r'Current DJ: </span>\n(.+?)<')
def wuvt(phenny, input): def wuvt(phenny, input):
""".wuvt - Find out what is currently playing on the radio station WUVT.""" """.wuvt - Find out what is currently playing on the radio station WUVT."""
try: try:
playing = web.get('http://www.wuvt.vt.edu/playlists/latest_track.php') data = web.get('https://www.wuvt.vt.edu/playlists/latest_track',
djpage = web.get('http://www.wuvt.vt.edu/playlists/current_dj.php') headers={'Accept': "application/json"})
trackinfo = web.json(data)
except: except:
raise GrumbleError('Cannot connect to wuvt') raise GrumbleError("Failed to fetch current track from 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: dj = trackinfo['dj'].strip()
if dj.strip()[0:3] == 'DJ ': if dj[0:3] != 'DJ ':
phenny.reply('{0} is currently playing: {1} by {2}' dj = 'DJ {}'.format(dj)
.format(dj.strip(), song.strip(), artist.strip()))
else: phenny.say("{dj} is currently playing {title} by {artist}".format(
phenny.reply('DJ {0} is currently playing: {1} by {2}' dj=dj,
.format(dj.strip(), song.strip(), artist.strip())) title=trackinfo['title'].strip(),
else: artist=trackinfo['artist'].strip()))
phenny.reply('Cannot connect to wuvt')
wuvt.commands = ['wuvt'] wuvt.commands = ['wuvt']
wuvt.example = '.wuvt'