Is There Any Way To Check if a Twitch Stream Is Live Using Python?

后端 未结 7 479
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 18:44

I\'m just wondering if there is any way to write a python script to check to see if a twitch.tv stream is live?

I\'m not sure why my app engine tag was removed, but this

7条回答
  •  孤独总比滥情好
    2021-02-04 19:38

    Yes. You can use Twitch API call https://api.twitch.tv/kraken/streams/YOUR_CHANNEL_NAME and parse result to check if it's live.

    The below function returns a streamID if the channel is live, else returns -1.

    import urllib2, json, sys
    TwitchChannel = 'A_Channel_Name'
    def IsTwitchLive(): # return the stream Id is streaming else returns -1
        url = str('https://api.twitch.tv/kraken/streams/'+TwitchChannel)
        streamID = -1
        respose = urllib2.urlopen(url)
        html = respose.read()
        data = json.loads(html)
        try:
           streamID = data['stream']['_id']
        except:
           streamID = -1
        return int(streamID)
    

提交回复
热议问题