phenny-1/modules/wuvt.py

35 lines
1.1 KiB
Python
Raw Normal View History

2012-05-27 22:30:59 -04:00
#!/usr/bin/env python
"""
2015-03-05 19:14:46 -05:00
wuvt.py - WUVT now playing module for phenny
2012-05-27 22:30:59 -04:00
"""
from tools import GrumbleError
2012-05-27 22:30:59 -04:00
import web
2013-10-05 19:20:37 -04:00
def wuvt(phenny, input):
""".wuvt - Find out what is currently playing on the radio station WUVT."""
2012-05-27 22:30:59 -04:00
try:
2015-03-05 19:14:46 -05:00
data = web.get('https://www.wuvt.vt.edu/playlists/latest_track',
headers={'Accept': "application/json"})
trackinfo = web.json(data)
2013-06-09 01:27:24 -04:00
except:
2015-03-05 19:14:46 -05:00
raise GrumbleError("Failed to fetch current track from WUVT")
2015-04-05 22:11:52 -04:00
if 'listeners' in trackinfo:
phenny.say(
2016-01-12 13:02:25 -05:00
"{dj} is currently playing \"{title}\" by {artist} with "
"{listeners:d} online listeners".format(
2015-04-05 22:11:52 -04:00
dj=trackinfo['dj'],
title=trackinfo['title'],
artist=trackinfo['artist'],
listeners=trackinfo['listeners']))
else:
2016-01-12 13:02:25 -05:00
phenny.say("{dj} is currently playing \"{title}\" by {artist}".format(
2015-04-05 22:11:52 -04:00
dj=trackinfo['dj'],
title=trackinfo['title'],
artist=trackinfo['artist']))
2012-05-27 22:30:59 -04:00
wuvt.commands = ['wuvt']
2015-03-05 19:14:46 -05:00
wuvt.example = '.wuvt'