From 946171fccbbdf711220e6028a6d8604ae0aae42f Mon Sep 17 00:00:00 2001 From: Randy Date: Sun, 27 May 2012 22:30:59 -0400 Subject: [PATCH] wuvt module --- modules/wuvt.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 modules/wuvt.py diff --git a/modules/wuvt.py b/modules/wuvt.py new file mode 100644 index 0000000..1d7ba47 --- /dev/null +++ b/modules/wuvt.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +""" +wuvt.py - Phenny WUVT Module +Copyright 2012, Randy Nance, randynance.info + +http://github.com/randynobx/phenny/ +""" + +from urllib.error import URLError, HTTPError +import re +import web + +re.MULTILINE +r_play = re.compile(r'^(.*?) - (.*?)$') +r_dj = re.compile(r'Current DJ: \n(.+?)<') + +def wuvt(phenny, input) : + 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 (URLError, HTTPError): + return phenny.reply('Cannot connect to wuvt') + play= r_play.search(playing) + song = play.group(1) + artist = play.group(2) + dj = r_dj.search(djpage).group(1) + + if song and artist: + phenny.reply('DJ {0} is currently playing: {1} by {2}'.format(dj.strip(),song,artist)) + else: + phenny.reply('Cannot connect to wuvt') +wuvt.commands = ['wuvt']