Syntax: Select all
from steam import SteamID
...
steamid = SteamID.parse(player.steamid) # Parse a string containing one of multiple SteamID text representations
print("SteamID64: {}".format(steamid.to_uint64())) # SteamID64: 76561198026369554 -- also known as CommunityID. Is an int!
print("SteamID2: {}".format(steamid.to_steamid2())) # SteamID2: STEAM_1:0:33051913 -- was STEAM_0:0:33051913 (note first zero) before
print("SteamID3: {}".format(steamid.to_steamid3())) # SteamID3: [U:1:66103826]
Heavy weapons stuff - custom profile URL
Syntax: Select all
import json
from urllib.request import urlopen
from steam import SteamID
STEAM_WEB_API_KEY = "XXXXXXXXXXXXXXXXXXXXXXX" # Get your own @ http://steamcommunity.com/dev/apikey
STEAM_GET_PLAYER_SUMMARIES_URL = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={api_key}&steamids={steamid}"
...
steamid64 = SteamID.parse(player.steamid).to_uint64()
with urlopen(STEAM_GET_PLAYER_SUMMARIES_URL.format(api_key=STEAM_WEB_API_KEY, steamid=steamid64)) as response:
profile_info = json.loads(response.read().decode('utf-8'))['response']['players'][0]
print("Custom URL: {}".format(profile_info['profileurl'])) # Custom URL: http://steamcommunity.com/id/its_iPlayer/
I'd also like to note that trying to work with SteamID64 as an integer in languages like JavaScript will lead to last digits being equal to zeros - that's because JS can't natively handle big numbers.
Oh, and this code will fail every Tuesday due to Steam maintenance.
Bonus. Sample response for GetPlayerSummaries:
Syntax: Select all
{
"response": {
"players": [
{
"steamid": "76561198026369554",
"communityvisibilitystate": 3,
"profilestate": 1,
"personaname": "iPlayer",
"lastlogoff": 1471880022,
"commentpermission": 1,
"profileurl": "http://steamcommunity.com/id/its_iPlayer/",
"avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/13/13aef0f2b873850870d1466efacbe83bbb7664b0.jpg",
"avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/13/13aef0f2b873850870d1466efacbe83bbb7664b0_medium.jpg",
"avatarfull": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/13/13aef0f2b873850870d1466efacbe83bbb7664b0_full.jpg",
"personastate": 1,
"primaryclanid": "103582791431436014",
"timecreated": 1275902481,
"personastateflags": 0
}
]
}
}