import requests class ChanInfoError(Exception): pass; class ChannelInfo: """A class for obtaining info for a Twitch Channel""" def __init__(self,channel,client_id): self.channel = channel; self.client_id = client_id; self.resp = requests.get("https://api.twitch.tv/kraken/streams/{!s}?client_id={!s}".format(channel,client_id)); if self.resp.json().get("error") != None: raise ChanInfoError("{status} {error} - \"{message}\"".format(**self.resp.json())) """If the channel is online, returns true. Else, returns false.""" def isOnline(self): return self.resp.json().get('stream') != None; """Get the status of the stream.""" def getStatus(self): return self.resp.json()['stream']['channel']['status'] """Get the game.""" def getGame(self): return self.resp.json()['stream']['game'] """Get whether to display "playing" or "being".""" def getDisplay(self): return self.getGame() == "Creative" """Get viewer count.""" def getViewers(self): return self.resp.json()['stream']['viewers'] """Get embed frame (for HTML)""" def getEmbed(self, width=950, height=700, autoplay=False): return "".format(self.channel,str(autoplay).lower(),width,height) """Update data, just runs the init again.""" def update(self): self.__init__(self.channel,self.client_id)