Skip to content

Instantly share code, notes, and snippets.

@maxcountryman
Created September 13, 2011 18:58
Show Gist options
  • Select an option

  • Save maxcountryman/1214717 to your computer and use it in GitHub Desktop.

Select an option

Save maxcountryman/1214717 to your computer and use it in GitHub Desktop.
radio redit plugin for an irctk app
# radioreddit stuff
@bot.command
def status(stream):
streams = [
'rock',
'electronic',
'hiphop',
'random',
'talk',
'indie'
]
url = 'http://radioreddit.com/api/'
if not stream:
urls = [url + '{0}/status.json'.format(stream) for stream in streams]
urls.append(url + 'status.json')
i = 0
for url in urls:
i += int(json.loads(urllib.urlopen(url).read())['listeners'])
listeners = 'There are {0} listeners currently'.format(i)
return bot.irc.send_reply(listeners)
elif stream == 'main':
status = urllib.urlopen(url + 'status.json')
elif stream in streams:
status = urllib.urlopen(url + '{0}/status.json'.format(stream))
status = json.loads(status.read())['listeners']
listeners = 'There are {0} listeners currently'.format(status)
bot.irc.send_reply(listeners)
@bot.command
def np(stream):
'''usage: .np [stream]'''
streams = [
'rock',
'electronic',
'hiphop',
'random',
'talk',
'indie'
]
if stream in streams:
url = 'http://radioreddit.com/api/{0}/status.json'
results = urllib.urlopen(url.format(stream))
else:
results = urllib.urlopen('http://radioreddit.com/api/status.json')
results = json.loads(results.read())['songs']['song'][0]
url = str(results['reddit_url'])
result = chr(2) + results['title'] + chr(2) + ' -- ' + results['artist'] \
+ ' ' + '(Redditor: {0})'.format(results['redditor']) + ' ' + \
bitly.shorten(longurl=url)['url']
if stream:
np = 'Now playing on the {0} stream: '.format(stream) + result
bot.irc.send_reply(np)
else:
np = 'Now playing on Radio Reddit: ' + result
bot.irc.send_reply(np)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment