Skip to content

Instantly share code, notes, and snippets.

@franga2000
Created May 24, 2020 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franga2000/9228b4b303185e8db5dacb0dd84e3aa7 to your computer and use it in GitHub Desktop.
Save franga2000/9228b4b303185e8db5dacb0dd84e3aa7 to your computer and use it in GitHub Desktop.
"""
STEAM GAME MATCHER SCRIPT
by franga2000
Users can be given as command line parameters. If no parameters are given, you will be prompted to type them in.
Users with vanity URLS (steamcommunity.com/id/my_name) can be entered as my_name, users without vanity URLs (steamcommunity.com/profile/1234567) can be entered as #1234567.
(Be careful to enclose numeric ids in single quotes when entering as command line parameters, so the # isn't interpreted as a comment)
A Steam API key should be provided in the environment variable STEAM_API_KEY.
This script requires the 'steam' package, available here: https://pypi.python.org/pypi/steam
"""
import os
import sys
from steam import WebAPI
STEAM_API_KEY = os.environ["STEAM_API_KEY"]
api = WebAPI(STEAM_API_KEY)
def get_steam_id(username):
resp = api.ISteamUser.ResolveVanityURL(vanityurl=username)["response"]
if resp["success"] == 1:
return resp["steamid"]
return None
def get_games(steamid):
resp = api.IPlayerService.GetOwnedGames(steamid=steamid, include_appinfo=True, include_played_free_games=True, include_free_sub=False, appids_filter=[])
return resp["response"]["games"]
def get_game_info(gameid):
resp = api.ISteamUserStats.GetSchemaForGame(appid=gameid)
return resp["game"]
def get_common_games(steam_ids):
game_sets = []
for steam_id in steam_ids:
games = get_games(steam_id)
game_sets.append(set([game["appid"] for game in games]))
common_game_ids = set.intersection(*game_sets)
for game_id in common_game_ids:
yield next(g for g in games if g["appid"] == game_id)
if __name__ == "__main__":
usernames = []
if len(sys.argv) > 1:
usernames += sys.argv[1:]
# print("Usernames: %s" % ", ".join(usernames))
else:
print("Type usernames one by one and press enter")
print("When you're done, press enter again to run")
i = 1
while True:
username = input(str(i) + ". ")
if username:
usernames.append(username)
else:
break
i += 1
steam_ids = [username.replace("#", "") for username in usernames if username.startswith("#")]
steam_ids += [get_steam_id(username) for username in usernames if not username.startswith("#")]
common_games = list(get_common_games(steam_ids))
print()
print("Found %i games in common:" % len(common_games))
for game in common_games:
print(" -", game["name"])
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment