Last active
November 15, 2020 17:33
-
-
Save Laura7089/cf45a5b7058973736d25dea258994262 to your computer and use it in GitHub Desktop.
Get steam games shared between accounts using custom urls/steamID64s. Requires https://pypi.org/project/steam/ and an API key, found at https://steamcommunity.com/dev/apikey.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from os import environ, path | |
from sys import argv | |
from steam.steamid import SteamID | |
from steam.webapi import WebAPI | |
def get_api(): | |
if path.exists("./apiKey.txt"): | |
with open("./apiKey.txt", "rt") as file: | |
api_key = file.read().replace("\n", "") | |
elif environ.get("STEAM_API_KEY") is not None: | |
api_key = environ["STEAM_API_KEY"] | |
else: | |
api_key = input("Steam API Key> ") | |
return WebAPI(api_key) | |
def get_apps_list(): | |
return { | |
game["appid"]: game["name"] | |
for game in API.call("ISteamApps.GetAppList")["applist"]["apps"] | |
} | |
def gather_ids(): | |
if len(argv) == 1: | |
print( | |
"Type custom URL values or steam ID64s with line separation, to end the list input a blank line" | |
) | |
ids = list() | |
current_id = "null" | |
while current_id != "": | |
current_id = input("> ") | |
ids.append(current_id) | |
else: | |
ids = argv[1:] | |
for userid in ids: | |
try: | |
yield SteamID(int(userid, 10)) | |
except ValueError: | |
yield SteamID.from_url(f"https://steamcommunity.com/id/{userid}") | |
def get_user_games(steamid): | |
result = API.call( | |
"IPlayerService.GetOwnedGames", | |
steamid=steamid, | |
include_appinfo=False, | |
include_played_free_games=True, | |
appids_filter=0, | |
include_free_sub=False, | |
) | |
return {game["appid"] for game in result["response"]["games"]} | |
API = get_api() | |
APPS_LIST = get_apps_list() | |
if __name__ == "__main__": | |
users = gather_ids() | |
libraries = map(get_user_games, users) | |
games = sorted( | |
APPS_LIST.get(appid) for appid in set.intersection(*libraries) | |
if appid in APPS_LIST) | |
print("\n".join(games)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment