Update twitch.py
Added colours to the message (L36), added error catch for if user has no stream or videos (L16), added currently-streaming check (L21)
This commit is contained in:
parent
9f5fc95d5b
commit
4ef52d3762
1 changed files with 18 additions and 4 deletions
|
@ -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)
|
||||||
title = soup.findAll('span', {'class': 'real_title js-title'})[0].text
|
try:
|
||||||
|
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 np:
|
if online:
|
||||||
return "%s: %s playing %s" % (title, name, playing)
|
if np:
|
||||||
|
return u"%s: %s playing %s (\x033\x02Online now!\x02\x0f)" % (title, name, playing)
|
||||||
|
else:
|
||||||
|
return u"%s: %s (\x033\x02Online now!\x02\x0f)" % (title, name)
|
||||||
else:
|
else:
|
||||||
return "%s: %s" % (title, name)
|
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)
|
||||||
|
|
Reference in a new issue