我試圖獲得使用Steam API玩TF2遊戲的時間。我目前使用: -使用Steam WebAPI獲取玩遊戲的總時間
http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=440&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&steamid=xxxxxxxxxxxxxxxxx&format=xml
然後通過XML過濾和提取時間起到與每個類(例如焦(Pyro.accum.iPlayTime)等)的。這工作正常,但我認爲錯過了MVM類使我的最終值不正確(我的代碼,在Python中,返回977時,當在線網站說超過1600小時)。添加MVM類(可能還有其他類)可能會提供不正確的結果,但它會使代碼非常冗長。
所以我想知道在Steam Web API中是否有一個調用,只需要給我總時間而不必去所有的提取和添加?
我已經瀏覽了Steam Web API開發者頁面,但是找不到任何我之後的參考。
添加的代碼:
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
謝謝。
馬庫斯
@安迪,謝謝你的回覆安迪。你添加了哪個iPlayTime?顯然所有與這些類有關的(即Pyro,Engie,Medic等)。你是否也需要包含所有的MvM等價類?我還注意到還有與地圖相關的iPlaytime標籤,我假設我不包含這些標籤。如果我添加了所有相關的iPlayTime,我相信我可以得到正確的值,但是我的問題更關注於是否有更簡單的方法來獲得總時間,例如,一個簡單的iTotalPlayTime標籤?我會嘗試在上面添加我的代碼(以前從未這樣做過):) – Markus
@Andy,我的個人資料是76561197960964581.代碼總共返回了我987個小時,但是當我看着TF2Stats這樣的地方時,它告訴我我超過1600小時。 – Markus
@安迪,謝謝安迪,我將在那時離開它,並假設類包括正常和mvm地圖。 – Markus