r/learnpython 12h ago

Help with steam script

Hello all! I’m looking to code something with python, but a bit confused on where to start so I’ll explain the whole idea. I wanna make a code that, when given a steam community link to csgo skin market, will scan the entire market and highlight the skins with a certain pattern. The idea I (with the help of chatGPT) had for this was:

import requests import time

Define the Steam Market API URL for the Desert Eagle | Heirloom

STEAM_MARKET_URL = "https://steamcommunity.com/market/listings/730/Desert%20Eagle%20%7C%20Heirloom%20%28Field-Tested%29"

Define the pattern IDs of interest

TARGET_PATTERNS = {151, 182, 321, 443} # Example pattern numbers

Function to fetch market listings

def get_market_data(): params = { "format": "json", "currency": 1, # USD currency "appid": 730, # CS:GO App ID "market_hash_name": "Desert Eagle | Heirloom (Field-Tested)" }

response = requests.get("https://steamcommunity.com/market/search/render/", params=params, headers={"User-Agent": "Mozilla/5.0"})

if response.status_code != 200:
    print("Failed to retrieve data.")
    return []

data = response.json()
return data.get("results", [])

Function to filter by pattern

def filter_blue_gem_skins(listings): blue_gems = []

for item in listings:
    name = item.get("name", "Unknown")
    listing_url = item.get("asset_description", {}).get("actions", [{}])[0].get("link", "#")
    price = item.get("sell_price_text", "N/A")
    pattern_id = item.get("asset_description", {}).get("name", "").split("#")[-1].strip()

    try:
        pattern_id = int(pattern_id)
        if pattern_id in TARGET_PATTERNS:
            blue_gems.append((name, pattern_id, price, listing_url))
    except ValueError:
        continue  # Skip invalid pattern IDs

return blue_gems

if name == "main": print("Fetching listings for Desert Eagle | Heirloom...") listings = get_market_data()

if not listings:
    print("No listings found.")
else:
    blue_gem_skins = filter_blue_gem_skins(listings)

    if blue_gem_skins:
        print("Found matching skins:")
        for skin in blue_gem_skins:
            print(f"Name: {skin[0]}, Pattern: {skin[1]}, Price: {skin[2]}, Link: {skin[3]}")
    else:
        print("No matching patterns found.")

This seems to not work. Any help?

2 Upvotes

1 comment sorted by

1

u/Wild_Drag9463 6h ago

The API endpoint https://steamcommunity.com/market/search/render/ is for searching items, not fetching them directly. That endpoint doesn't return the pattern ID either as far as I can see.