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
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:
Valve's official Web API reference: https://partner.steamgames.com/doc/webapi_overview
An unofficial reference from the SteamDB creators: https://lab.xpaw.me/steam_api_documentation.html
Related
I am working in collecting a data set that crossreferences a track's audio features and the Billboard's chart data set available on Kaggle. I am trying to get each song's URI in order to then get its audio features, and I defined the following function:
def get_track_uri(track_title, sp):
result = sp.search(track_title, type="track", limit=1)
if result['tracks']['total'] > 0:
track_uri = result['tracks']['items'][0]['uri']
return track_uri
else:
return None
and then it goes through the Billboard's 'song' column in order to create a new column with the URIs.
cleandf['uri'] = cleandf['song'].apply(lambda x: get_track_uri(x, sp))
So, I left it running for about 40 min and I noticed that it got stuck in a sleep method from Spotipy which I gathered was because I was making a lot of requests to the Spotify API. How can I be able to go around this if I'm trying to go through 50,000 rows? I could maybe make it wait between search queries but it will easily take what, 15 hours? Also, there probably is a way to directly get the audio features without me getting the URI's, but it still would need to go through all of the rows.
I am trying to get a full database of all active players career stats in the NBA.
I'm relatively new to Python and am trying to figure out a way to iterate a loop function by looking up the playerID for each PlayerCareerStat data frame. Ultimately I will summarize and group the data so its easier to read but I am trying to return a list of all players career stats by season.
I am able to use the players.get_active_players() endpoint to return a list of all players with their player_id: [1]: https://i.stack.imgur.com/BFxgv.png
With that, I am tryin to loop the Player_id through each data frame in the PlayerCareerStats() endpoint ... I think? Since the parameter for this endpoint requires a single player_id I can't seem to get all the players. Please see picture [1]: https://i.stack.imgur.com/skM8Y.png
Does anyone know how I might be able to get the output I am trying to find?
When you create a function, it will end when it reaches return. So your function returns the player id, and doesn't move on to the part where you are trying to pull the career stats.
So get rid of that return player['id'], and the function should run all the way through:
from nba_api.stats.static import players
from nba_api.stats.endpoints import playercareerstats
import pandas as pd
def get_nba_id():
nba_players = players.get_active_players()
for player in nba_players:
career_stats = playercareerstats.PlayerCareerStats(player_id=player['id'])
career_df = career_stats.get_data_frames()[0]
career_df['NAME'] = player['full_name']
print(career_df)
I am currently creating a program where I want to fetch stock data from yahoo finance using the yahoo_finance module. However, I want to fetch data for 4 stocks using what i assume would be a loop. Here's the basic structure I thought of using:
from yahoo_finance import Share
ticker_symbols = ["YHOO", "GOOG", "AAPL"]
i = 0
while i < 4:
company = Share(str(i))
print (company.get_open())
i += 1
The main problem I need assistance with is how I would construct a loop that iterates over all the ticker_symbols. As you can tell from my "try" above I am completely clueless, since I am new to python. A secondary problem I have is how I would fetch data from 30 days ago up to current date using the module. Maybe I should have resorted to web scraping but it seems so much more difficult.
to loop over a list you can just do :
for symbol in ticker_symbols :
company = Share(symbol)
That's basic python ! I will advise you to follow a small tutorial to learn the python basics.
You can get historical daily data using Share(symbol).get_historical('aDate'). Here you can find all the available methods for the package : https://pypi.python.org/pypi/yahoo-finance
good luck with that
You need to iterate over the ticker_symbols list and simply ditch the while loop:
from yahoo_finance import Share
ticker_symbols = ["YHOO", "GOOG", "AAPL"]
for i in ticker_symbols:
company = Share(i)
print (company.get_open())
I'm trying to get access to the amount of TF2 time played using the Steam API. I'm currently using:-
http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=440&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&steamid=xxxxxxxxxxxxxxxxx&format=xml
And then filter through the XML and extracting the time played relating to each of the classes (e.g. pyro (Pyro.accum.iPlayTime), etc). This worked ok but I think missing the MVM classes made my final value incorrect (my code, in Python, returned 977 when online sites say over 1600 hours). Adding the MVM classes (plus possibly others) may provide th ecorrect result but it's making the code very long winded.
So I was wondering if there is a call in the Steam Web API that will just give me the total time played without having to go though all the extracting and adding?
I have looked through the Steam Web API Developer page, but can't find any reference to what I'm after.
Added Code:
if __name__ == '__main__':
import urllib2
import xml.etree.ElementTree as ET
import datetime
timeKISA = 0
playerStatsKISA = urllib2.urlopen('http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=440&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&steamid=xxxxxxxxxxxxxxxxx&format=xml')
statsKISA = playerStatsKISA.read()
theStatsKISA = ET.fromstring(statsKISA)
for stat in theStatsKISA.findall("./stats/stat"):
if stat.find('name').text.startswith('Scout.accum.iPlayTime') or \
stat.find('name').text.startswith('Soldier.accum.iPlayTime') or \
stat.find('name').text.startswith('Engineer.accum.iPlayTime') or \
stat.find('name').text.startswith('Medic.accum.iPlayTime') or \
stat.find('name').text.startswith('Spy.accum.iPlayTime') or \
stat.find('name').text.startswith('Sniper.accum.iPlayTime') or \
stat.find('name').text.startswith('Demoman.accum.iPlayTime') or \
stat.find('name').text.startswith('Heavy.accum.iPlayTime') or \
stat.find('name').text.startswith('Pyro.accum.iPlayTime'):
timeKISA = timeKISA + int(stat.find('value').text)
finalTimeKISA = timeKISA / 60 / 60
KISATime = ('KISA_Time=' + str(finalTimeKISA) + ' hours')
print KISATime
Thank you.
Markus
Pulling my comments into an answer,
It is my understanding that the *.accum.iPlayTime fields are cumulative for your place time as that class regardless of game mode or map. Based on my own stats (and a glance at a few others on my friend list), this matches exactly what Steam Community reports that play time is. Additionally, it is reporting that your playtime matches these fields on your TF2 Achievements page.
A couple notes:
The summary page on a player's profile does not seem to match the actual stats that the achievements page shows. I'm unsure if this is a Steam Community issue or a summary of additional fields. However, the achievements page, which has detailed break downs of play time by class, longest life, etc. is using the same data as the GetUserStatsForGame API call.
You have a very minor formating issue in your code. The very last print KISATime is indented one to many times and therefore prints the KISA_Time = line multiple times. If you pull it out of the for loop, you will only get the print line once.
If you change your finalTimeKISA = timeKISA / 60 / 60 to be decimal 60.0 you will get the decimal answers. Otherwise, as is, you will only receive an integer answer.
i want to know how much time(secend) do i need to get my whole facebook wall from json(graph api)
it takes about 190 seconds to get my whole wall's post (maybe 2000 posts and 131pages(json))
follow is python code. that code is just reading the posts.
is there any problem in my code? and should i cut my response time?
accessToken = "Secret"
requestURL = "https://graph.facebook.com/me/feed?access_token="+accessToken
beforeSec = time.time()*1000
pages = 1
while 1:
read = urllib.urlopen(requestURL).read()
read = json.loads(read)
data = read["data"]
for i in range(0, len(data)):
pass
try:
requestURL = read["paging"]["next"]
pages+=1
except:
break
afterSec = time.time()*1000
print afterSec - beforeSec
It depends offcourse on how big the users wall is ... They have released a new batch function : http://developers.facebook.com/docs/reference/api/batch/
Mayb you can use that?
Your code is synchronous, so you download the pages one by one.
It's very slow, you could download several pages in parallel instead.
Greenlet are the new hype for Python paraller computing, so give a try to gevent.
Well, this is provided you can get the next page before downloading the entire previous page of course. Try to see if you can get the next paging in a quick way.