def test_sids(self): ID64 = 76561198014028523 profile_batch_friends = api.interface("ISteamUser").GetFriendList(steamid = ID64) profile_batch_testsids = [friend["steamid"] for friend in profile_batch_friends["friendslist"]["friends"]] friend_list = user.friend_list(ID64) self.assertEqual(set(profile_batch_testsids), set(map(lambda x: str(x.steamid), friend_list)))
def test_big_list(self): # As of writing this my list has ~150 friends. I don't plan on going below 100. # If I should become a pariah or otherwise go under 100 this should probably be changed. # TODO: Implement GetFriendList in steamodd proper friends = api.interface("ISteamUser").GetFriendList(steamid = self.VALID_ID64) testsids = [friend["steamid"] for friend in friends["friendslist"]["friends"]] self.assertEqual(set(testsids), set(map(lambda x: str(x.id64), user.profile_batch(testsids))))
def getIDFromUsername(username): api.key.set("A946F35FD4CD2C8F3896F7970B4A6DCF") response = api.interface("ISteamUser").ResolveVanityUrl(vanityurl = username) if response['response']['success'] == 42: return 42; else: return response['response']['steamid']
def list_user_games(STEAM_ID): games = interface('IPlayerService').GetOwnedGames(steamid=STEAM_ID, include_appinfo=1) game_count = games['response']['game_count'] user_games = [] for i in range(0,game_count): data = (games['response']['games'][i]) user_games.append(data['name']) user_games = str(user_games) replace = ["[","]","'"] for i in range(0,len(replace)): user_games = user_games.replace(replace[i],'') return user_games
def test_sids(self): ID64 = 76561198014028523 profile_batch_friends = api.interface("ISteamUser").GetFriendList( steamid=ID64) profile_batch_testsids = [ friend["steamid"] for friend in profile_batch_friends["friendslist"]["friends"] ] friend_list = user.friend_list(ID64) self.assertEqual(set(profile_batch_testsids), set(map(lambda x: str(x.steamid), friend_list)))
def getProfile(userID): errorCount = 0 profile = [] keepGoing = True while keepGoing: try: if errorCount == 10: return -4, "API timed out 10 times, could not get profile" keepGoing = False break # Get a user's game library games = api.interface("IPlayerService").GetOwnedGames(steamid = userID, include_appinfo = 1, include_played_free_games = 1) # Handle the (rare) case where user has no games if 'game_count' not in games["response"]: return -2, "Your profile is private!" break if games["response"]["game_count"] == 0: return -1, "You don't own any games!" break for game in games['response']['games']: appid = str(game['appid']) data = game data['appid'] = appid profile.append(data) break except api.HTTPTimeoutError: errorCount += 1 # User's profile is private except api.HTTPError as e: if str(e) == "Server connection failed: Unauthorized (401)": return -2, "Your profile is private!" else: return -3, e break except Exception as e: return -3, e break updateGameData(games['response']['games']) return 0, profile
def test_big_list(self): # As of writing this my list has ~150 friends. I don't plan on going below 100. # If I should become a pariah or otherwise go under 100 this should probably be changed. # TODO: Implement GetFriendList in steamodd proper friends = api.interface("ISteamUser").GetFriendList( steamid=self.VALID_ID64) testsids = [ friend["steamid"] for friend in friends["friendslist"]["friends"] ] self.assertEqual( set(testsids), set(map(lambda x: str(x.id64), user.profile_batch(testsids)))) self.assertEqual( set(testsids), set(map(lambda x: str(x.id64), user.bans_batch(testsids))))
def steamStats(user): import os import time import steam from steam.api import interface steamToken = settings.getSteamToken() urlBase = 'http://steamcommunity.com/id/' status = ['offline', 'online', 'busy', 'away', 'snoozed', 'looking to trade', 'looking to play'] steam.api.key.set(steamToken) try: steamID = steam.user.vanity_url(urlBase + user) profile = steam.user.profile(steamID) except: return "That profile is private or does not exist. :worried: " else: friend_list = steam.user.friend_list(steamID) numFriends = friend_list.count games = interface('IPlayerService').GetOwnedGames(steamid=steamID, include_appinfo=1) numGames = games['response']['game_count'] currentGame = profile.current_game[2] message = "<{}{}|{}> is currently {}. ".format(urlBase, user, profile.persona, status[profile.status]) if (profile.status == 0): message = message + "This user was last online at {}. ".format(time.asctime(time.localtime(time.mktime(profile.last_online)))) message = message + "This user is level {}, owns {} games and has {} friends. ".format(profile.level, numGames, numFriends) if (currentGame == None): message = message + "This user is in a currently not in a game." else: message = message + "This user is currently playing {}.".format(currentGame[0:(len(currentGame))]) return message
def main(): game_dict = {} steam.api.key.set(os.environ.get("STEAM_KEY")) vanity_url = steam.user.vanity_url('http://steamcommunity.com/id/maddchickenz') steamid = vanity_url.id64 profile = steam.user.profile(vanity_url) games = interface("IPlayerService").GetOwnedGames(steamid=steamid, include_appinfo=1) with open("steam_games.txt", "w+") as f: pass game_list = [] for game in games["response"]["games"]: game_obj = Game(game) game_list.append(game_obj) game_dict[game_obj.appid] = Game(game) with open("steam_games.txt", "a+") as f: f.write("%s\n" % game["appid"] ) #steam_scraper.start_scraper() try: table = Table.create("random_steam_test", schema=[HashKey("steam_app_id"), RangeKey("tag")], throughput={"read": 1, "write": 1 }) except Exception as e: print e.message if "Table already exists" in e.message: table = Table("random_steam_test") else: raise with open("steam.json", "r") as f: data = json.load(f) for tag in data: appid = tag["appid"] game = game_dict[appid] game.tags = tag["tag"] for game_tag in game.tags: print game_tag table.put_item({"steam_app_id": game.appid, "tag": game_tag})
def index(self): promo_list = app.config['PROMO_LIST'] form = Promo() form.promo.choices = promo_list if form.validate_on_submit(): promo_id = form.promo.data url_list = form.profile_urls.data url_list = [x.strip() for x in url_list.split('\n')] response = "" for url in url_list: steam_id_info = get_steam_id_from_url(url) if steam_id_info[0] is True: steam_id = steam_id_info[1] try: grant = interface('ITFPromos_440').GrantItem( data={ "promoID": promo_id, "steamID": steam_id }) if bool(grant.get('result').get('status')) is True: response += url + " - Success\n" except (HTTPError, HTTPTimeoutError): response += url + " - Steam error. Please try again later.\n" else: response += url + " - " + steam_id_info[1] + "\n" form.profile_urls.data = response return self.render('admin/distribute.html', form=form)
def index(self): promo_list = app.config['PROMO_LIST'] form = Promo() form.promo.choices = promo_list if form.validate_on_submit(): promo_id = form.promo.data url_list = form.profile_urls.data url_list = [x.strip() for x in url_list.split('\n')] response = "" for url in url_list: steam_id_info = get_steam_id_from_url(url) if steam_id_info[0] is True: steam_id = steam_id_info[1] try: grant = interface('ITFPromos_440').GrantItem(data={"promoID": promo_id, "steamID": steam_id}) if bool(grant.get('result').get('status')) is True: response += url + " - Success\n" except (HTTPError, HTTPTimeoutError): response += url + " - Steam error. Please try again later.\n" else: response += url + " - " + steam_id_info[1] + "\n" form.profile_urls.data = response return self.render( 'admin/distribute.html', form=form )