Steam API get historical player count of specific game
Asked Answered
H

2

7

I am using steam api with python in order to get the number of players playing a game such as Dota 2.

import requests
import numpy as np
import pandas as pd

def main():

    header = {"Client-ID": "F07D7ED5C43A695B3EBB01C28B6A18E5"}

    appId = 570
    game_players_url = 'https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?format=json&appid=' + appId
    game_players = requests.get(game_players_url, headers=header)

    print("Game name: Dota 2" + ", Player count: " + str(game_players.json()['response']['player_count']))


if __name__ == '__main__':
    main()

This gets me the correct current number of players for a specific game (in this case dota 2), however what i need is historical data concerning the player count of this specific game. This should be possible, since this site has the information that i desire and they are probably getting their data from the Steam API.

Any help would be greatly appreciated!

Thank you

Hispania answered 31/8, 2017 at 14:22 Comment(4)
They are gathering the data and persisting it, hence why they have an historical data. In order for you to have the historical data, you should persist it as well.Winery
I thought about this, but I find it weird that they have all the data for every game on steam, for so many years back. That's why i think that it might be possible that the steam api is feeding all these data.Hispania
Consider reading github.com/SteamRE/SteamKit , there might be some obscure api method undocumented by Steam. But steemdb is pretty old. and even though the domains registration dates 2013, they do have data back to 2011.Winery
I would hide any sensible information in the code, such as Client-Id.Expostulation
Y
6

ilhicas pointed it out correctly in the comments: SteamDB has this historical data because they have been collecting and saving it for years, every single day. Official release for SteamDB was around 2010 so that's why they have so much data.

I have had a similar problem, looked around extensiveley and came to this conclusion:

There is no Steam Web API method for historical player count of a specific game.

In case you do not believe me:

Yamamoto answered 4/9, 2017 at 12:36 Comment(0)
F
0

I know, that it's been a few years, but I wanted to share my solution, that I've been using for a while. I just came about this post, because I was searching for a better way.

import aiohttp
import http
from bs4 import BeautifulSoup



async def playercount(gameid):
    url = f'https://steamcharts.com/app/{gameid}'
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'}

    async with aiohttp.ClientSession(headers=headers) as session:
        async with session.get(url) as response:
            if response.status != 200:
                return{"error": {"code": response.status, "message": http.HTTPStatus(response.status).phrase}}
            html = await response.text()

    soup = BeautifulSoup(html, 'html.parser')
    data = {}
    count = 0
    for stats in soup.find_all('div', class_='app-stat'):
        soup2 = BeautifulSoup(str(stats), 'html.parser')
        for stat in soup2.find_all('span', class_='num'):
            stat = str(stat).replace('<span class="num">', '').replace('</span>', '')
            if count == 0:
                data['Current Players'] = stat
            elif count == 1:
                data['Peak Players 24h'] = stat
            elif count == 2:
                data['Peak Players All Time'] = stat
            count += 1
    return data
Firm answered 31/3 at 8:36 Comment(2)
While this code may answer the question, providing additional context regarding why and/or how this code answers the question will make it more useful for others in the future. For instance, given that this question is nearly seven years old, does your solution include functions/libraries that didn't exist when the question was originally posted? ThanksYoga
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Milagrosmilam

© 2022 - 2024 — McMap. All rights reserved.