Spaces:
Sleeping

File size: 1,766 Bytes
270511d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
main.py  β€”  Steam CS2 Inventory Scraper
Usage:
    python main.py
    python main.py https://steamcommunity.com/profiles/<steamid>/inventory/
"""
import sys

from fetcher import fetch_inventory_from_site, convert_to_steamdt_url
from parser import extract_and_enrich_items
from reporter import print_inventory_summary

# ══════════════════════════════════════════════════════════════════════════════
# ENTRY POINT
# ══════════════════════════════════════════════════════════════════════════════

DEFAULT_URL = "https://steamcommunity.com/profiles/76561198080075870/inventory/"


def scrape_steam_inventory(steam_url: str) -> list[dict] | None:
    """
    Full pipeline:
      1. Convert Steam URL β†’ SteamDT URL
      2. Fetch raw API JSON via headless browser
      3. Parse + enrich items
      4. Print summary
      5. Return item list
    """
    steamdt_url = convert_to_steamdt_url(steam_url)
    print(f"Steam URL  : {steam_url}")
    print(f"SteamDT URL: {steamdt_url}")

    raw_data = fetch_inventory_from_site(steamdt_url)
    if not raw_data:
        print("ERROR: No data received from SteamDT.")
        return None

    items = extract_and_enrich_items(raw_data)
    if not items:
        print("ERROR: No items found in API response.")
        return None

    print_inventory_summary(items)
    return items


if __name__ == "__main__":
    url = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_URL
    scrape_steam_inventory(url)