def __init__(self, username, stats_file_name=None):
     self.key, self.domain = self.get_key_and_domain()
     self.steamuserinfo = ISteamUser(steam_api_key=self.key)
     self.steamstatsinfo = ISteamUserStats(steam_api_key=self.key)
     self.steamplayerinfo = IPlayerService(steam_api_key=self.key)
     self.steamid = self.getSteamID(username)
     self.stats_file_name = stats_file_name
     self.gameList = None
     self.achievementList = None
     logging.basicConfig(filename='example.log', level=logging.DEBUG)
Esempio n. 2
0
def get_user_profile(user):
    userinfo = User()
    steamuser = ISteamUser()
    playerservice = IPlayerService()
    regex = re.compile('^\d{17}$')
    if regex.match(user):
        userinfo.steamid = user
    else:
        userinfo.steamid = steamuser.resolve_vanity_url(
            user)['response']['steamid']
    usersummary = steamuser.get_player_summaries(
        userinfo.steamid)['response']['players'][0]
    for key in list(usersummary.keys()):
        if isinstance(usersummary[key], int):
            exec('userinfo.' + key + ' = ' + str(usersummary[key]))
        else:
            exec('userinfo.' + key + ' = ' + '"' + usersummary[key] + '"')

    # Group ID '103582791429521408' is often encountered.
    # In hex, that ID is '0x170000000000000' which has 0 in the
    # lower 32bits. There is no actual group ID, just the universe,
    # account type identifiers, and the instance.
    # https://developer.valvesoftware.com/wiki/SteamID
    if userinfo.primaryclanid:
        if (int(userinfo.primaryclanid) & 0x00000000FFFFFFFF) == 0:
            userinfo.primaryclanid = None

    games_response = playerservice.get_recently_played_games(
        userinfo.steamid)['response']
    if 'games' in games_response:
        recent_games = games_response['games']
    else:
        recent_games = []
    steam_level = playerservice.get_steam_level(
        userinfo.steamid)['response']['player_level']
    for game in recent_games:
        # Sometimes, games don't have keys for 'name', or 'img_*_url' apparently.
        if 'img_icon_url' in game and 'appid' in game:
            game[
                'img_icon_url'] = "http://media.steampowered.com/steamcommunity/public/images/apps/{appid}/{hash}.jpg".format(
                    appid=game['appid'], hash=game['img_icon_url'])
            game[
                'img_logo_url'] = "http://media.steampowered.com/steamcommunity/public/images/apps/{appid}/{hash}.jpg".format(
                    appid=game['appid'], hash=game['img_logo_url'])
    userinfo.recentlyplayedgames = recent_games
    userinfo.steamlevel = steam_level

    try:
        userinfo.profileurlname = re.search(r"id\/(.*)\/",
                                            userinfo.profileurl).groups()[0]
    except:
        pass

    return userinfo
Esempio n. 3
0
def get_user_profile(user):
    userinfo = User()
    steamuser = ISteamUser()
    playerservice = IPlayerService()
    regex = re.compile('^\d{17}$')
    if regex.match(user):
        userinfo.steamid = user
    else:
        userinfo.steamid = steamuser.resolve_vanity_url(user)['response']['steamid']
    usersummary = steamuser.get_player_summaries(userinfo.steamid)['response']['players'][0]
    for key in list(usersummary.keys()):
        if isinstance(usersummary[key], int):
            exec('userinfo.' + key + ' = ' + str(usersummary[key]))
        else:
            exec('userinfo.' + key + ' = ' + '"' + usersummary[key] + '"')

    # Group ID '103582791429521408' is often encountered.
    # In hex, that ID is '0x170000000000000' which has 0 in the 
    # lower 32bits. There is no actual group ID, just the universe,
    # account type identifiers, and the instance.
    # https://developer.valvesoftware.com/wiki/SteamID
    if userinfo.primaryclanid:
        if (int(userinfo.primaryclanid) & 0x00000000FFFFFFFF) == 0:
            userinfo.primaryclanid = None

    games_response = playerservice.get_recently_played_games(userinfo.steamid)['response']
    if 'games' in games_response:
        recent_games = games_response['games']
    else:
        recent_games = []
    steam_level = playerservice.get_steam_level(userinfo.steamid)['response']['player_level']
    for game in recent_games:
        # Sometimes, games don't have keys for 'name', or 'img_*_url' apparently.
        if 'img_icon_url' in game and 'appid' in game:
            game['img_icon_url'] = "http://media.steampowered.com/steamcommunity/public/images/apps/{appid}/{hash}.jpg".format(appid=game['appid'], hash=game['img_icon_url'])
            game['img_logo_url'] = "http://media.steampowered.com/steamcommunity/public/images/apps/{appid}/{hash}.jpg".format(appid=game['appid'], hash=game['img_logo_url'])
    userinfo.recentlyplayedgames = recent_games
    userinfo.steamlevel = steam_level

    try:
        userinfo.profileurlname = re.search(r"id\/(.*)\/", userinfo.profileurl).groups()[0]
    except:
        pass

    return userinfo
Esempio n. 4
0
    def collect_data(self):
        now = time.time()
        data = {}

        steamuserinfo = ISteamUser(steam_api_key=self.steam_api_key)
        steamid = steamuserinfo.resolve_vanity_url(
            "entrymissing")['response']['steamid']
        playerinfo = IPlayerService(steam_api_key=self.steam_api_key)
        played_games = playerinfo.get_recently_played_games(
            steamid)['response']
        playtime = [game['playtime_2weeks'] for game in played_games['games']]
        owned_games = playerinfo.get_owned_games(steamid)['response']

        data[self.prefix + '.game_count_2w'] = [(now,
                                                 played_games['total_count'])]
        data[self.prefix + '.minutes_played_2w'] = [(now, sum(playtime))]
        data[self.prefix + '.owned_games'] = [(now, owned_games['game_count'])]

        return data
def mySampleTestCode():
    # Just prints out one game so you can see the structure of the game stats.
    with open('api-config.json', 'r') as configurationFile:
        config = json.loads(configurationFile.read())
    key, domain = config['key'], config['domain']
    steamuserinfo = ISteamUser(steam_api_key=key)
    steamstatsinfo = ISteamUserStats(steam_api_key=key)
    steamplayerinfo = IPlayerService(steam_api_key=key)

    steamprofile = steamuserinfo.resolve_vanity_url('adamclmns')
    steamid = steamprofile['response']['steamid']

    print(" STEAM PROFILE DATA SAMPLE:")
    print(steamid)
    print("\n\n")

    print(" GAME DATA FOR FALLOUT 4 ")
    print()
    print("\n\n")
Esempio n. 6
0
def get_user_profile(user):
    userinfo = User()
    steamuser = ISteamUser()
    playerservice = IPlayerService()
    regex = re.compile("^\d{17}$")
    if regex.match(user):
        userinfo.steamid = user
    else:
        userinfo.steamid = steamuser.resolve_vanity_url(user)["response"]["steamid"]
    usersummary = steamuser.get_player_summaries(userinfo.steamid)["response"]["players"][0]
    for key in list(usersummary.keys()):
        if isinstance(usersummary[key], int):
            exec("userinfo." + key + " = " + str(usersummary[key]))
        else:
            exec("userinfo." + key + " = " + '"' + usersummary[key] + '"')

    recent_games = playerservice.get_recently_played_games(userinfo.steamid)["response"]["games"]
    steam_level = playerservice.get_steam_level(userinfo.steamid)["response"]["player_level"]
    for game in recent_games:
        game[
            "img_icon_url"
        ] = "http://media.steampowered.com/steamcommunity/public/images/apps/{appid}/{hash}.jpg".format(
            appid=game["appid"], hash=game["img_icon_url"]
        )
        game[
            "img_logo_url"
        ] = "http://media.steampowered.com/steamcommunity/public/images/apps/{appid}/{hash}.jpg".format(
            appid=game["appid"], hash=game["img_logo_url"]
        )
    userinfo.recentlyplayedgames = recent_games
    userinfo.steamlevel = steam_level

    try:
        userinfo.profileurlname = re.search(r"id\/(.*)\/", userinfo.profileurl).groups()[0]
    except:
        pass

    return userinfo
def get_player_id(profile_name: str, steam_api_key: str) -> int:
    user_info = ISteamUser(steam_api_key=steam_api_key)
    steamid = user_info.resolve_vanity_url(profile_name)['response']['steamid']
    return steamid
Esempio n. 8
0
from __future__ import print_function
from steamwebapi.api import ISteamUser, IPlayerService, ISteamUserStats
import json

steamID = [76561198048730871, 76561198180821795, 76561198008911412]
steamuserinfo = ISteamUser()
playerserviceinfo = IPlayerService()

AMOUNT = 1000

count = 0
while len(steamID) < AMOUNT:
    state = steamuserinfo.get_player_summaries(steamID[count])['response']['players'][0]['communityvisibilitystate']
    if state == 3:
        friendslist = steamuserinfo.get_friends_list(steamID[count])['friendslist']['friends']
        for i in friendslist:
            if int(i['steamid']) not in steamID:
                steamID.append(int(i['steamid']))
    print('\r{0}%'.format(round(len(steamID) / AMOUNT * 100)), end="", flush=True)
    count += 1
print('\n')
print('nUsers: ', len(steamID))
json_file = open('Resources/steamkey{0}.json'.format(AMOUNT), 'w')
json.dump(steamID, json_file)
json_file.close()
Esempio n. 9
0
from steamwebapi.api import ISteamUser, IPlayerService, ISteamUserStats

steamuserinfo = ISteamUser(steam_api_key='DF0E97F40E0BEE667B0BF01B6626A9DA')
steamid = steamuserinfo.resolve_vanity_url("profileURL")['response']['steamid']
print(steamuserinfo.resolve_vanity_url("profileURL"))
class SteamAchievementDataMiner():
    # Constructor
    def __init__(self, username, stats_file_name=None):
        self.key, self.domain = self.get_key_and_domain()
        self.steamuserinfo = ISteamUser(steam_api_key=self.key)
        self.steamstatsinfo = ISteamUserStats(steam_api_key=self.key)
        self.steamplayerinfo = IPlayerService(steam_api_key=self.key)
        self.steamid = self.getSteamID(username)
        self.stats_file_name = stats_file_name
        self.gameList = None
        self.achievementList = None
        logging.basicConfig(filename='example.log', level=logging.DEBUG)

    # GetSteamID
    def getSteamID(self, username):
        steamprofile = self.steamuserinfo.resolve_vanity_url(username)
        logging.debug("!!! DEBUG: - STEAM PROFILE DATA - for username %s" %
                      username)
        logging.debug(steamprofile)
        return steamprofile['response']['steamid']

    # getGameList
    def getGameList(self):
        self.gameList = self.steamplayerinfo.get_owned_games(
            self.steamid)['response']['games']
        logging.debug("!!! DEBUG: - STEAM GAME LIST FROM PROFILE")
        logging.debug(self.gameList)
        return self.gameList

    # getAchievements from gamelist
    def getAchievements(self, game_list):
        achievement_list = []
        csvRow = ""
        for game in game_list:
            appid, title = game['appid'], game['name']
            csvRow += ("appid: %s , Title: %s , " % (appid, title))

            try:
                achievements = self.steamstatsinfo.get_player_achievements(
                    self.steamid, appid)
                achievement_list.append(achievements)
                csvRow += ("achievements available: %i \n" %
                           len(achievement_list)
                           )  # !!!!! LAST FIELD IN CSV HAS NO TRAILING COMMA
            except:
                csvRow += ("achievements available: NA \n"
                           )  # !!!!! LAST FIELD IN CSV HAS NO TRAILING COMMA
                pass
                # This is incase there are no achievements for a given
                # game, or if there is an error due to rate limiting
            self.writeStatsRow(csvRow)

        self.achievementList = achievement_list
        return achievement_list

    def writeStatsRow(self, data_to_try_to_write):
        if self.stats_file_name != None:
            with open(self.stats_file_name, 'a') as file_appender:
                file_appender.write(data_to_try_to_write)
        else:
            print(data_to_try_to_write)

    @staticmethod
    def get_key_and_domain():
        with open('api-config.json', 'r') as configurationFile:
            config = json.loads(configurationFile.read())
        return config['key'], config['domain']

    @staticmethod
    def dumpToFile(fileName, dataToWrite):
        with open(fileName, 'w') as outputFile:
            outputFile.write(json.dumps(dataToWrite + "\n"))
from steamwebapi.api import ISteamUser
from requests import get
import json
from bs4 import BeautifulSoup as BS

STEAM_API_KEY = "C66900DC016ACA765416952C6514E546"  # if empty get it here https://steamcommunity.com/dev/apikey

steam_user_info = ISteamUser(steam_api_key=STEAM_API_KEY)

# ЛЮБОЙ парсинг может вдруг не заработать
# https://store.steampowered.com/api/appdetails?appids=967390


def represent_Int(a):
    try:
        int(a)
        return True
    except ValueError:
        return False


def get_steam_id_from_url(profile_url=str):
    steam_id = ''
    url_components = profile_url.split('/')
    for i in range(len(url_components)):
        if url_components[i] == 'profiles' or url_components[i] == 'id':
            steam_id = str(url_components[i + 1])
    if represent_Int(
            steam_id
    ):  # if custom id int: id = int(id)  else: id = resolve(custom id)
        return int(steam_id)