Skip to content

Instantly share code, notes, and snippets.

@mg393
Created July 15, 2012 23:48
Show Gist options
  • Save mg393/3119259 to your computer and use it in GitHub Desktop.
Save mg393/3119259 to your computer and use it in GitHub Desktop.
Check if someone is online on steam in python 3
import urllib.request
import json
import sys
def isOnline(api_key, steam_id): #Steam ID is the 64bit one
req_headers = {'User-Agent': 'Python script'}
url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" + api_key + "&steamids=" + steam_id + "&format=json"
req = urllib.request.Request(url, data=None, headers=req_headers, origin_req_host=None)
response = urllib.request.urlopen(req)
content = response.read()
data = json.loads(content.decode('utf8'))
if data["response"]["players"][0]["personastate"] == 0: #0 = offline
return False
elif data["response"]["players"][0]["personastate"] == 1 or data["response"]["players"][0]["personastate"] == 2 or data["response"]["players"][0]["personastate"] == 3: #1 = online, 2 = busy, 3 = away
return True
else:
print("Error: Unknown persona state")
input("Press enter to continue...")
sys.exit()
@nodis-eli
Copy link

how do i use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment