Twitch API get historical viewers count of game

916 Views Asked by At

I am using Twitch api with python to get the total number of viewers for a specific game such as Dota 2. The following code gets the current viewer count for a game:

import requests


def main():

    header = {"Client-ID": "477xu1lvl2jiqzk9s0e3vc8rgip9os"}

    search_game_url = 'https://api.twitch.tv/kraken/search/games?query=dota&type=suggest'
    search_game = requests.get(search_game_url, headers = header)
    search_game_total = search_game.json()['games'][0]
    print("Name: " + str(search_game_total['name']) + ", Popularity: " + str(search_game_total['popularity']))


if __name__ == '__main__':
    main()

What I need to do is to get the total history of viewers count. In example, I want to get the viewer count of a game, for every week for the past five year. Can anyone help me with that ??

Thank youu so so much !!

1

There are 1 best solutions below

0
On

If you print the entire dictionary you get this

{
   "_links":{
      "self":"https://api.twitch.tv/kraken/search/games?query=dota&type=suggest"
   },
   "games":[
      {
         "localized_name":"Dota 2",
         "box":{
            "template":"https://static-cdn.jtvnw.net/ttv-boxart/Dota%202-{width}x{height}.jpg",
            "large":"https://static-cdn.jtvnw.net/ttv-boxart/Dota%202-272x380.jpg",
            "small":"https://static-cdn.jtvnw.net/ttv-boxart/Dota%202-52x72.jpg",
            "medium":"https://static-cdn.jtvnw.net/ttv-boxart/Dota%202-136x190.jpg"
         },
         "locale":"",
         "name":"Dota 2",
         "logo":{
            "template":"https://static-cdn.jtvnw.net/ttv-logoart/Dota%202-{width}x{height}.jpg",
            "large":"https://static-cdn.jtvnw.net/ttv-logoart/Dota%202-240x144.jpg",
            "small":"https://static-cdn.jtvnw.net/ttv-logoart/Dota%202-60x36.jpg",
            "medium":"https://static-cdn.jtvnw.net/ttv-logoart/Dota%202-120x72.jpg"
         },
         "_links":{

         },
         "_id":29595,
         "popularity":35436,
         "giantbomb_id":32887
      }
   ]
}

I don't see a value for the entire history of views for dota inside of here. However, if you can find that data elsewhere, just grab that total and divide by number of weeks in 5 years. Not sure where you can find that though.