From d963ac2e70f9c7ffd443bc517f6a6e1a6fea6265 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Thu, 5 Mar 2015 16:14:46 -0800 Subject: [PATCH] update wuvt module for new site --- modules/test/test_wuvt.py | 4 ++-- modules/wuvt.py | 38 ++++++++++++++------------------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/modules/test/test_wuvt.py b/modules/test/test_wuvt.py index 046b0c8..7cff1fc 100644 --- a/modules/test/test_wuvt.py +++ b/modules/test/test_wuvt.py @@ -15,7 +15,7 @@ class TestWuvt(unittest.TestCase): def test_wuvt(self): wuvt(self.phenny, None) - out = self.phenny.reply.call_args[0][0] - m = re.match('^DJ .* is currently playing: .* by .*$', out, + out = self.phenny.say.call_args[0][0] + m = re.match('^DJ .* is currently playing .* by .*$', out, flags=re.UNICODE) self.assertTrue(m) diff --git a/modules/wuvt.py b/modules/wuvt.py index a25dff2..eece7a6 100644 --- a/modules/wuvt.py +++ b/modules/wuvt.py @@ -1,39 +1,29 @@ #!/usr/bin/env python """ -wuvt.py - Phenny WUVT Module -Copyright 2012, Randy Nance, randynance.info - -http://github.com/randynobx/phenny/ +wuvt.py - WUVT now playing module for phenny """ from tools import GrumbleError -import re import web -re.MULTILINE -r_play = re.compile(r'^(.*?) - (.*?)$') -r_dj = re.compile(r'Current DJ: \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') + data = web.get('https://www.wuvt.vt.edu/playlists/latest_track', + headers={'Accept': "application/json"}) + trackinfo = web.json(data) 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) + raise GrumbleError("Failed to fetch current track from WUVT") - if song and artist: - if dj.strip()[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') + dj = trackinfo['dj'].strip() + if dj[0:3] != 'DJ ': + dj = 'DJ {}'.format(dj) + + phenny.say("{dj} is currently playing {title} by {artist}".format( + dj=dj, + title=trackinfo['title'].strip(), + artist=trackinfo['artist'].strip())) wuvt.commands = ['wuvt'] +wuvt.example = '.wuvt'