Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import os
- import webbrowser
- import urllib.request
- import json
- import random
- print("Steam Roulette")
- time.sleep(1)
- if os.path.exists('apikey.cfg') == True:
- print("API file found")
- else:
- file222 = open("apikey.cfg","w")
- file222.close()
- apikeyfile = open("apikey.cfg","r+")
- if apikeyfile.readline() == "SteamAPIKEY:\n":
- print("Found a preexisting API key, using that!")
- apikey = apikeyfile.readline()
- print(apikey)
- apikeyfile.close()
- else:
- apikeyfile.close()
- print("In order to use this tool you require a Steam Web API key.")
- print("You can get this from the steam website. Login on the webpage that was just opened and follow the instructions.")
- print("When you are given a API key, paste it into this prompt, then press enter! The key will then be saved, so you don't have to type it in again!")
- webbrowser.open("https://steamcommunity.com/dev/apikey", new=2, autoraise=True)
- apikey = input()
- print("Saving the API key to disk...")
- apikeyfileow = open("apikey.cfg","w")
- apikeyfileow.write("SteamAPIKEY:\n")
- apikeyfileow.write(apikey)
- apikeyfileow.close()
- print("Saved!")
- print("This program requires a SteamID to run. Input a full vanity URL OR a steam64ID for the user.")
- steamURLunparsed = input()
- if steamURLunparsed.startswith("http") == True:
- steamURLsplit = steamURLunparsed.split("/",)
- steamURL = steamURLsplit[4]
- print("Resolving URL...")
- try:
- urllib.request.urlretrieve("https://api.steampowered.com/ISteamUser/ResolveVanityURL/v1/?key="+apikey+"&vanityurl="+steamURL,"User.PICACACHE")
- except urllib.error.HTTPError:
- print("Something went wrong while trying to contact the Steam Web API, terminating program...")
- time.sleep(3.5)
- exit()
- userjson = open("./User.PICACACHE")
- userjsoninuse = True
- usercontent = userjson.read()
- decodeduser = json.loads(usercontent)
- steamusernumber = decodeduser['response']['steamid']
- print("User "+steamURL+" has the ID "+steamusernumber)
- elif steamURLunparsed.startswith("7656119") == True:
- steamusernumber = steamURLunparsed
- userjsoninuse = False
- else:
- print("That's not a valid URL or ID, terminating program.")
- time.sleep(1.5)
- exit()
- print("Getting a list of games that this player owns...")
- try:
- urllib.request.urlretrieve("https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?key="+apikey+"&steamid="+steamusernumber,"Games.PICACACHE")
- except urllib.error.HTTPError:
- print("Something went wrong while trying to contact the Steam Web API, terminating program...")
- time.sleep(3.5)
- exit()
- badgeslist1 = open("Games.PICACACHE","r")
- badgeslist2 = badgeslist1.read()
- decodedbadgeslist1 = json.loads(badgeslist2)
- badgeapps = list()
- count = int("0")
- for x in decodedbadgeslist1['response']['games']:
- keys = (list(x.keys()))
- values = (list(x.values()))
- for i in range(1,len(keys)):
- if keys[i] == "appid":
- count = count+1
- badgeapps.append(str(values[i]))
- print("Found "+str(count)+" games!")
- print("Selecting random game...")
- gamenumber = random.randint(0,count-1)
- print("Selected appid "+badgeapps[gamenumber]+", launching now!")
- webbrowser.open('steam://rungameid/'+badgeapps[gamenumber])
- time.sleep(3)
- print("Clearing PICACACHE files...")
- badgeslist1.close()
- if userjsoninuse == True:
- userjson.close()
Add Comment
Please, Sign In to add comment