Ejemplo n.º 1
0
	def get_games_from(self, url, url_property):
		url_info = self._open_url(url)
	
		all_games = []
		if url_info is not None:
			soup = BeautifulSoup(url_info)
			# Finds all of the sections containing game info
			games = soup.findAll("a", "search_result_row")
			appid_re = r"http://store.steampowered.com/%s/([0-9]*).*" % url_property
			
			for game in games:
				price = 0
				# If the price is in "<strike>" tags, it's on sale, and we have to get it with another method
				price_text = game.find('div', {'class': 'col search_price'})
				sale = price_text.find('strike')
	
				name = game.find("h4").text
				if name:
					formatted_game = name.replace("&reg;", '') # Replace the (R) symbol
					formatted_game = formatted_game.replace('&trade;', '') # Replace the (TM) symbol
				else:
					name = ""
	
				if sale:
					try:
						price = float(sale.text[5:])
					except ValueError:
						price = 0.00
				else:
					try:
						price = float(price_text.text[5:])
					except ValueError:
						price = 0.00
					
				appid = re.search(appid_re, game['href'])
				if appid:
				    appid = appid.group(1)
				try:
					appid = int(appid)
				except:
					appid = -1
	
				store_url = "http://store.steampowered.com/%s/%s" % (url_property, appid)
	
				#logging.error("appid: %s store: %s" % (appid, store_url))
	
				image_url = self._image_url(appid, url_property)
	
				current_game = {'name': formatted_game, 'appid': appid, 'price': price, 'store_url': store_url, 'image_url': image_url}
				all_games.append(current_game)
			return all_games
		else:
			return None
Ejemplo n.º 2
0
    def get_groups(self):
        url = "http://steamcommunity.com/profiles/%s/groups/" % self.steam_id
        soup = BeautifulSoup(self._open_url(url))

        groups = soup.findAll('div', 'groupBlockMedium')
        all_groups = []
        for group in groups:
            group = group.find('a')
            if group:
                group_url = group['href']
                if group_url:

                    all_groups.append(group_url)
        return all_groups
Ejemplo n.º 3
0
	def get_groups(self):
		url = "http://steamcommunity.com/profiles/%s/groups/" % self.steam_id
		soup = BeautifulSoup(self._open_url(url))

		groups = soup.findAll('div', 'groupBlockMedium')
		all_groups = []
		for group in groups:
			group = group.find('a')
			if group:
				group_url = group['href']
				if group_url:
					
					all_groups.append(group_url)
		return all_groups
Ejemplo n.º 4
0
    def get_wishlist(self):
        """Retrieves all appids for games on a user's wishlist."""
        url = "http://steamcommunity.com/profiles/%s/wishlist" % self.steam_id
        soup = BeautifulSoup(self._open_url(url))

        wish_games = soup.findAll("div", "wishlistRow")
        all_games = []

        for game in wish_games:
            current_id = game['id']
            if current_id:
                search = re.search(r'([0-9]+)', current_id)
                if search:
                    all_games.append(int(search.group(1)))

        return all_games
Ejemplo n.º 5
0
	def get_wishlist(self):
		"""Retrieves all appids for games on a user's wishlist."""
		url = "http://steamcommunity.com/profiles/%s/wishlist" % self.steam_id	
		soup = BeautifulSoup(self._open_url(url))

		wish_games = soup.findAll("div", "wishlistRow")
		all_games = []

		for game in wish_games:
			current_id = game['id']
			if current_id:
				search = re.search(r'([0-9]+)', current_id)
				if search:
					all_games.append(int(search.group(1)))

		return all_games
Ejemplo n.º 6
0
    def get_games_from(self, url, url_property):
        url_info = self._open_url(url)

        all_games = []
        if url_info is not None:
            soup = BeautifulSoup(url_info)
            # Finds all of the sections containing game info
            games = soup.findAll("a", "search_result_row")
            appid_re = r"http://store.steampowered.com/%s/([0-9]*).*" % url_property

            for game in games:
                price = 0
                # If the price is in "<strike>" tags, it's on sale, and we have to get it with another method
                price_text = game.find('div', {'class': 'col search_price'})
                sale = price_text.find('strike')

                name = game.find("h4").text
                if name:
                    formatted_game = name.replace("&reg;",
                                                  '')  # Replace the (R) symbol
                    formatted_game = formatted_game.replace(
                        '&trade;', '')  # Replace the (TM) symbol
                else:
                    name = ""

                if sale:
                    try:
                        price = float(sale.text[5:])
                    except ValueError:
                        price = 0.00
                else:
                    try:
                        price = float(price_text.text[5:])
                    except ValueError:
                        price = 0.00

                appid = re.search(appid_re, game['href'])
                if appid:
                    appid = appid.group(1)
                try:
                    appid = int(appid)
                except:
                    appid = -1

                store_url = "http://store.steampowered.com/%s/%s" % (
                    url_property, appid)

                #logging.error("appid: %s store: %s" % (appid, store_url))

                image_url = self._image_url(appid, url_property)

                current_game = {
                    'name': formatted_game,
                    'appid': appid,
                    'price': price,
                    'store_url': store_url,
                    'image_url': image_url
                }
                all_games.append(current_game)
            return all_games
        else:
            return None
Ejemplo n.º 7
0
def get_user(steam_id, stats=None):
    """
    Return codes for get_user():
    1 - New user succesfully added
    2 - User update succeeded
    3 - New user was private, not added
    4 - Current user, no need for update, sucesfully returned
    5 - Update succeeded, but private profile
    6 - Update failed - too soon since last update
    7 - Bad Steam ID

    """

    # If the user inputs a URL that doesn't have the 64 bit id, then we have to retrieve that
    # with a call to Steam to see if it's valid. Since we don't always want to do that,
    # we store the "orig_id" (the full url) in memcache, mapped to the actual id if needed.
    # Cuts down on the amount of Steam API calls needed per user lookup.
    if stats is None:
        stats = utils.retrieve_stats()
    orig_id = steam_id
    id_retrieved = False
    cached_id = memcache.get(orig_id)
    if cached_id is not None:
        id_retrieved = True
        steam_id = cached_id

    if id_retrieved is False:
        steam_match = re.match(steam_re, steam_id)
        if steam_match:
            steam_id = steam_match.string
        else:
            if re.match(r'https?://steamcommunity.com/.*', steam_id):
                try:
                    profile = urllib2.urlopen(steam_id)
                except ValueError:
                    return None, 7
                soup = BeautifulSoup(profile)
                scripts = soup.findAll('script')
                found = False
                for script in scripts:
                    text = script.text.strip()
                    if text[:15] == 'g_rgProfileData':
                        json_info = json.loads(text[18:-1])
                        steam_id = json_info['steamid']
                        found = True
                if found is False:
                    return None, 7
            else:
                try:
                    profile = urllib2.urlopen(
                        "http://steamcommunity.com/id/%s" % steam_id)
                except ValueError:
                    return None, 7

                soup = BeautifulSoup(profile)
                scripts = soup.findAll('script')
                found = False
                for script in scripts:
                    text = script.text.strip()
                    if text[:15] == 'g_rgProfileData':
                        json_info = json.loads(text[18:-1])
                        steam_id = json_info['steamid']
                        found = True
                if found is False:
                    return None, 7
        memcache.add(orig_id, steam_id)

    user = SteamIds.get_by_id(steam_id)
    counters.pingpong_incr(queries_counter)
    # User already exists, decide what to do
    if user:
        # If this is true, there have been updates to the db. Update the user, if possible.
        if stats.games_last_updated > user.last_updated or stats.hltb_last_updated > user.last_updated:
            info_to_update = SteamUsers(steam_id, api_key)
            # User profile is invisible. Still update what we have on record, but warn the user
            # to update w/public profile.
            if info_to_update.visibility is False:
                user, rc = _update_user(user, info_to_update, stats)
                return user, rc
            #User's profile was visible, fully sucessful update.
            else:
                user, rc = _update_user(user, info_to_update, stats)
                return user, rc
        # Current user, no need for update, just return for display.
        else:
            return user, 4

    else:
        user_info = SteamUsers(steam_id, api_key)
        # This is not a Steam ID
        if user_info.good_id is False:
            return None, 7
        # This is not a public profile. Can't view.
        elif user_info.visibility is False:
            return None, 3
        # New user was succesfully added. FTW!
        else:
            user = add_user_to_ndb(user_info, stats)
            #increment_steamids()
            counters.pingpong_incr(steamids_counter)
            return user, 1
Ejemplo n.º 8
0
def get_user(steam_id, stats=None):
    """
    Return codes for get_user():
    1 - New user succesfully added
    2 - User update succeeded
    3 - New user was private, not added
    4 - Current user, no need for update, sucesfully returned
    5 - Update succeeded, but private profile
    6 - Update failed - too soon since last update
    7 - Bad Steam ID

    """

    # If the user inputs a URL that doesn't have the 64 bit id, then we have to retrieve that
    # with a call to Steam to see if it's valid. Since we don't always want to do that,
    # we store the "orig_id" (the full url) in memcache, mapped to the actual id if needed.
    # Cuts down on the amount of Steam API calls needed per user lookup.
    if stats is None:
        stats = utils.retrieve_stats()
    orig_id = steam_id
    id_retrieved = False
    cached_id = memcache.get(orig_id)
    if cached_id is not None:
        id_retrieved = True
        steam_id = cached_id

    if id_retrieved is False:
        steam_match = re.match(steam_re, steam_id)
        if steam_match:
            steam_id = steam_match.string
        else:
            if re.match(r'https?://steamcommunity.com/.*', steam_id):
                try:
                    profile = urllib2.urlopen(steam_id)
                except ValueError:
                    return None, 7
                soup = BeautifulSoup(profile)
                scripts = soup.findAll('script')
                found = False
                for script in scripts:
                    text = script.text.strip()
                    if text[:15] == 'g_rgProfileData':
                        json_info = json.loads(text[18:-1])
                        steam_id = json_info['steamid']
                        found = True
                if found is False:
                    return None, 7
            else:
                try:
                    profile = urllib2.urlopen("http://steamcommunity.com/id/%s" % steam_id)
                except ValueError:
                    return None, 7
    
                soup = BeautifulSoup(profile)
                scripts = soup.findAll('script')
                found = False
                for script in scripts:
                    text = script.text.strip()
                    if text[:15] == 'g_rgProfileData':
                        json_info = json.loads(text[18:-1])
                        steam_id = json_info['steamid']
                        found = True
                if found is False:
                    return None, 7
        memcache.add(orig_id, steam_id)

    user = SteamIds.get_by_id(steam_id)
    counters.pingpong_incr(queries_counter)
    # User already exists, decide what to do
    if user:
        # If this is true, there have been updates to the db. Update the user, if possible.
        if stats.games_last_updated > user.last_updated or stats.hltb_last_updated > user.last_updated:
            info_to_update = SteamUsers(steam_id, api_key)
            # User profile is invisible. Still update what we have on record, but warn the user
            # to update w/public profile.
            if info_to_update.visibility is False:
                user, rc = _update_user(user, info_to_update, stats)
                return user, rc
            #User's profile was visible, fully sucessful update.
            else:
                user, rc = _update_user(user, info_to_update, stats)
                return user, rc
        # Current user, no need for update, just return for display.
        else:
            return user, 4

    else:
        user_info = SteamUsers(steam_id, api_key)
        # This is not a Steam ID
        if user_info.good_id is False:
            return None, 7
        # This is not a public profile. Can't view.
        elif user_info.visibility is False:
            return None, 3
        # New user was succesfully added. FTW!
        else:
            user = add_user_to_ndb(user_info, stats)
            #increment_steamids()
            counters.pingpong_incr(steamids_counter)
            return user, 1