Merge pull request #68 from blha303/patch-1

Update twitch.py
This commit is contained in:
Luke Rogers 2013-06-21 01:49:04 -07:00
commit 1817609c9c

View file

@ -13,7 +13,15 @@ def twitch_url(match):
if not test(match.group(4).split("/")[1]): if not test(match.group(4).split("/")[1]):
return "Not a valid username" return "Not a valid username"
soup = http.get_soup("http://twitch.tv/" + location) soup = http.get_soup("http://twitch.tv/" + location)
try:
title = soup.findAll('span', {'class': 'real_title js-title'})[0].text title = soup.findAll('span', {'class': 'real_title js-title'})[0].text
except IndexError:
return "That user has no stream or videos."
online = True
try:
isplaying = soup.findAll('a', {'data-content_type': 'live'})[0];
except IndexError:
online = False
try: try:
name = soup.findAll('a', {'class': 'channel_name'})[0].text name = soup.findAll('a', {'class': 'channel_name'})[0].text
except IndexError: except IndexError:
@ -23,7 +31,13 @@ def twitch_url(match):
np = False np = False
else: else:
np = True np = True
if online:
if np: if np:
return "%s: %s playing %s" % (title, name, playing) return u"%s: %s playing %s (\x033\x02Online now!\x02\x0f)" % (title, name, playing)
else: else:
return "%s: %s" % (title, name) return u"%s: %s (\x033\x02Online now!\x02\x0f)" % (title, name)
else:
if np:
return u"%s: %s playing %s (\x034\x02Offline\x02\x0f)" % (title, name, playing)
else:
return u"%s: %s (\x034\x02Offline\x02\x0f)" % (title, name)