class UserOverview(APIView): def __init__(self): # Passed back res with all games parsed with correct information from out database self.res = {} self.isPrivate = False # Steamid we will set by the URL parameter @steamid self.steamid = None self.vacInfo = [] self.userDetails = [] self.libraryCost = 0 self.api = SteamApi() def getVacs(self): vacs = self.api.getVacInfo(self.steamid) print('vac res: ' + str(vacs)) self.res['vacinfo'] = vacs def getUserDetails(self): userDetails = self.api.getUserDetails(self.steamid) if userDetails['response']['players']['player'][0].get( 'communityvisibilitystate') == 1: self.isPrivate = True self.res['private'] = True self.res['userdetails'] = userDetails def get(self, request, *args, **kwargs): self.steamid = kwargs.get('steamid') self.getUserDetails() self.getVacs() return Response(self.res)
def __init__(self): self.sids = [] self.privateFriends = [] self.nonPrivateFriends = [] self.gameList = [] self.commonGames = [] self.res = {} self.api = SteamApi()
def __init__(self): # Passed back res with all games parsed with correct information from out database self.res = {} self.isPrivate = False # Steamid we will set by the URL parameter @steamid self.url = None self.steamid = None self.userDetails = [] self.IdOrVanity = None self.api = SteamApi()
class LocationBuilder(APIView): def __init__(self): self.steamid = None self.locations = [] self.res = {} self.api = SteamApi() # Function to take in the users location codes and grab the coordinates and return a list of [latitude, longitude] def coordinateBuilder(self, country, state, city): # Read the country code json file provided @https://github.com/Holek/steam-friends-countries codeFile = os.path.join(settings.STATIC_ROOT, 'json/steam_countries.json') with open(codeFile, encoding='utf8') as f: data = json.load(f) coordinates = data[str(country)].get('states')[str(state)].get( 'cities')[str(city)].get('coordinates') split = coordinates.split(',') return split def locationsBuilder(self): arrLat = [] arrLon = [] # Get friend list friends = self.api.getFriendsList(self.steamid) # Iterate friends and build the coordinates for f in friends: if f['player'][0].get('loccityid') is not None: country = f['player'][0]['loccountrycode'] state = f['player'][0]['locstatecode'] city = str(f['player'][0]['loccityid']) coordinates = self.coordinateBuilder(country, state, city) latitude = str(coordinates[0]) longitude = str(coordinates[1]) # If the coordinate is already in the list, it will show up directly on top of each other, # This catches that and adds some latitude to offset it slightly on the map if latitude in arrLat: dec = float(.03) latitude = float(latitude) latitude = dec + latitude latitude = str(round(latitude, 6)) arrLat.append(latitude) arrLon.append(longitude) self.locations.append({ 'name': f['player'][0]['personaname'], 'lat': latitude, 'lon': longitude, }) self.res['locations'] = self.locations def get(self, request, *args, **kwargs): self.steamid = kwargs.get('steamid') self.locationsBuilder() return Response(self.res)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Model Processor Instance self.processor = ModelProcessor() # In house API wrapper instance self.api = SteamApi() # Client object self.worker = SteamWorker()
class UserSearch(APIView): def __init__(self): # Passed back res with all games parsed with correct information from out database self.res = {} self.isPrivate = False # Steamid we will set by the URL parameter @steamid self.url = None self.steamid = None self.userDetails = [] self.IdOrVanity = None self.api = SteamApi() def getIdOrVanity(self): url = str(self.url) # Check if the profiles URL has the steamid, or is a vanity url if "steamcommunity" in url: # Is vanity, get the steamid from vanity with Steam API if "/id/" in url: vanityIDIndex = url.find('/id/') vanity = url[vanityIDIndex:].replace('/id/', '').replace('/', '') self.steamid = self.api.resolveVanity(vanity) # Is ID, just set steamid to ID in URL if "/profiles" in url: IDIndex = url.find('/profiles/') ID = url[IDIndex:].replace('/profiles/', '').replace('/', '') self.steamid = ID def getUserDetails(self): userDetails = self.api.getUserDetails(self.steamid) if userDetails['response']['players']['player'][0].get( 'communityvisibilitystate') == 1: self.isPrivate = True self.res['private'] = True self.res['userdetails'] = userDetails def get(self, request, *args, **kwargs): self.url = request.GET.get('url', '') print(str(self.url)) self.getIdOrVanity() self.getUserDetails() return Response(self.res)
class GetFriendList(APIView): def __init__(self): self.method = '/ISteamUser/GetFriendList/v0001/' # Steamid we will set by the URL parameter @steamid self.steamid = None self.res = {} self.api = SteamApi() def getFriends(self): friends = self.api.getFriendsList(self.steamid) self.res['friends'] = friends def get(self, request, *args, **kwargs): self.steamid = kwargs.get('steamid') self.getFriends() return Response(self.res)
def handle(self, *args, **options): # Appid to work with (either create new app in db, or edit update app) appid = 1388360 # Necessary objects we need to process app from steamkit # - api handler # - steamkit worker (and login) # - our model processor api = SteamApi() worker = SteamWorker() worker.login() processor = ModelProcessor() # Fake changenumber for test model processor command changenum = 1337 # Call processNewGame, or processExistingGame depending on you want to create # a new app in the db, or update and existing app in the DB processor.processNewGame(appid, changenum, worker, api)
def handle(self, *args, **options): # Steamkit client worker = SteamWorker() worker.login() # Our model processor to process games processor = ModelProcessor() # Api class to handle steam api requests api = SteamApi() while True: if worker.isConnected(): # See if there are any tasks if Task.objects.all(): # Loop through each task and start processing them for task in Task.objects.all(): # If the app already exists, we update it with processExistingGame() if Game.objects.filter(appid=task.appid).exists(): print('task is an existing app | appid: ' + str(task.appid)) task.processing = True processor.processExistingGame( task.appid, task.changenumber, worker, api) task.delete() # if the app doesn't exist, we create a new app with processNewGame else: print('task is New app | appid: ' + str(task.appid)) task.processing = True processor.processNewGame(task.appid, task.changenumber, worker, api) task.delete() time.sleep(10) else: print('Task model has NO tasks') time.sleep(10) else: print('Disconnected from steam, waiting for reconnect...') time.sleep(10)
def __init__(self): self.steamid = None self.locations = [] self.res = {} self.api = SteamApi()
class GetComparedGames(APIView): def __init__(self): self.sids = [] self.privateFriends = [] self.nonPrivateFriends = [] self.gameList = [] self.commonGames = [] self.res = {} self.api = SteamApi() def getGames(self): return None # Processes the SID parameters so we can get a compared list going def processIdParams(self, sids): for k, v in sids.items(): self.sids.append(v) return self.sids def getCommonGames(self): # Loop through each comparee for sid in self.sids: # Get their game app library userLib = self.api.getUserLibrary(sid) try: # Loop through each game and append it to the game list for game in userLib['response']['games']: self.gameList.append(game['appid']) self.nonPrivateFriends.append(sid) except KeyError: self.privateFriends.append(sid) self.res['privateFriends'] = self.privateFriends # https://stackoverflow.com/a/15812667 # stores all common appids in var 'out' counter = Counter(self.gameList) out = [ value for value, count in counter.items() if count == len(self.nonPrivateFriends) ] # Get each game from commongames from db or create it def threadGames(game): if Game.objects.filter(appid=game).exists(): dbgame = Game.objects.get(appid=game) try: price = dbgame.current_price.price except: price = None formatGame = { 'appid': str(dbgame.appid), 'name': dbgame.name, 'current_price': str(price), 'image': 'https://steamcdn-a.akamaihd.net/steam/apps/' + str(dbgame.appid) + '/header.jpg' } self.commonGames.append(formatGame) else: # Check if a task is already in existence for the given appid, if it already exists dont create another identical task if not Task.objects.filter(appid=str(game)).exists(): # Create a new task to process the app into our database Task.objects.create(appid=str(game), changenumber=1337) try: gameInfo = self.api.getAppDetails(game)[str(game)]['data'] # processor.processNewGame(appid, changenum, worker, api) formatGame = { 'appid': str(game), 'name': gameInfo.get('name'), 'current_price': None, 'image': gameInfo.get('header_image') } # Append the game to our games list we will pass back self.commonGames.append(formatGame) except: pass with ThreadPoolExecutor(max_workers=8) as executor: if bool(out): for game in out: executor.submit(threadGames, game) self.res['commonGames'] = self.commonGames def get(self, request, *args, **kwargs): self.processIdParams(request.query_params) self.getCommonGames() return Response(self.res)
def __init__(self): self.method = '/ISteamUser/GetFriendList/v0001/' # Steamid we will set by the URL parameter @steamid self.steamid = None self.res = {} self.api = SteamApi()