def get_item_price_history_from_page(game_id, item): """ Gets an item's latest price history """ url = f"https://steamcommunity.com/market/pricehistory/?appid={game_id}&market_hash_name={string_to_query_string(item)}" # Obtaining prices page = get_page(url) # Checking status of get_page if page is None: # Unsuccessful price price_history = [] else: # Successful price prices = page["prices"] # Obtaining price history price_history = [] for price in prices: point = PriceHistoryPoint( datetime.strptime(price[0][0:11], "%b %d %Y"), price[1], price[2]) price_history.append(point) # Returning return price_history
def get_item_details(item_name): """ Gets an item's details """ # Obtaining data data = get_page( f"https://steamcommunity.com/market/search/render/?norender=1&query={item_name}" ) new_data = [] for item in data["results"]: # Creating game game_addition = Game(item["asset_description"]["appid"]) # Obtaining item details item_addition = Item(item["asset_description"]["market_hash_name"], item["asset_description"]["icon_url"]) item_addition.add_price_history( get_item_price_history_from_page( item["asset_description"]["appid"], item["asset_description"]["market_hash_name"])) game_addition.add_item(item_addition) new_data.append(game_addition) # Returning return new_data
def get_item_count(game_id): """ Finds the amount of items a game has """ # Obtaining page content url = f"https://steamcommunity.com/market/search/render/?search_descriptions=0&sort_column=default&sort_dir=desc&norender=1&count=100&appid={game_id}&start=0" page = get_page(url) # Finding total number of items total_items = page["total_count"] return total_items
def test_get_page(): """ Test get_page Tested normal request, request when blocked """ # Variable url = "https://steamcommunity.com/market/priceoverview/?appid=730&market_hash_name=StatTrak%E2%84%A2%20M4A1-S%20|%20Hyper%20Beast%20(Minimal%20Wear)" # Testing successful request after being blocked # Getting blocked while get(url).status_code == 200: continue # Ensuring that the function gets the success page = get_page(url) assert page["success"] # Testing bad url page = get_page("https://steamcommunity.com/market/pricehistory/?appid=263920&market_hash_name=Unlimited%20Mint%20&%20Chit") assert page is None # Testing normal successful request sleep(60) page = get_page(url) assert page["success"]
def get_items_basic_details_from_page(game_id, start_position): """ Finds the item name from a given render page """ # Getting item page url = f"https://steamcommunity.com/market/search/render/?search_descriptions=0&sort_column=default&sort_dir=desc&norender=1&count=100&appid={game_id}&start={start_position}" page = get_page(url) page = page["results"] # Obtaining item details items = [] for item in page: items.append( Item(item["hash_name"], item["asset_description"]["icon_url"])) return items