Merge pull request #198 from daboross/patch-4

Fix twitch plugin - Don't assume that data has any elements
This commit is contained in:
Luke Rogers 2014-01-15 12:41:09 -08:00
commit ae1c9d0788

View file

@ -92,8 +92,9 @@ def twitch_lookup(location):
views = views + "s" if not views[0:2] == "1 " else views views = views + "s" if not views[0:2] == "1 " else views
return h.unescape(fmt.format(title, channel, playing, views)) return h.unescape(fmt.format(title, channel, playing, views))
else: else:
data = http.get_json("http://api.justin.tv/api/stream/list.json?channel=" + channel)[0] data = http.get_json("http://api.justin.tv/api/stream/list.json?channel=" + channel)
if data: if data and len(data) >= 1:
data = data[0]
title = data['title'] title = data['title']
playing = data['meta_game'] playing = data['meta_game']
viewers = "\x033\x02Online now!\x02\x0f " + str(data["channel_count"]) + " viewer" viewers = "\x033\x02Online now!\x02\x0f " + str(data["channel_count"]) + " viewer"
@ -102,7 +103,10 @@ def twitch_lookup(location):
print viewers print viewers
return h.unescape(fmt.format(title, channel, playing, viewers)) return h.unescape(fmt.format(title, channel, playing, viewers))
else: else:
data = http.get_json("https://api.twitch.tv/kraken/channels/" + channel) try:
data = http.get_json("https://api.twitch.tv/kraken/channels/" + channel)
except:
return
title = data['status'] title = data['status']
playing = data['game'] playing = data['game']
viewers = "\x034\x02Offline\x02\x0f" viewers = "\x034\x02Offline\x02\x0f"