Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2025 RandomProgramm3r

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68 changes: 60 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Steam Market Scraper Parser
# Steam Market Parser

[![Linting](https://github.com/RandomProgramm3r/Steam-Market-Scraper/actions/workflows/linting.yml/badge.svg)](https://github.com/RandomProgramm3r/Steam-Market-Scraper/actions)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[<img src="https://steamcommunity.com/favicon.ico" width="20" alt="Steam Community Market" />](https://steamcommunity.com/market/)

## TOC
Expand All @@ -15,6 +17,8 @@
- [🧩 Usage](#-usage)
- [🔨 Function Signature](#-function-signature)
- [📤 Example](#-example)
- [🔁 Synchronous usage](#-synchronous-usage)
- [⚡ Asynchronous usage](#-asynchronous-usage)


## 📋 Description
Expand Down Expand Up @@ -77,13 +81,13 @@ For code consistency and quality checks, use Ruff - a unified linter/formatter:

```bash
# Run linting checks.
ruff check .
ruff check

# Auto-fix fixable lint issues
ruff check . --fix
ruff check --fix

# Format code.
ruff format .
ruff format
```


Expand Down Expand Up @@ -115,12 +119,12 @@ def market_scraper(

## 📤 Example

### 🔁 Synchronous usage
```python
import data
import scraper

# Example usage: Fetch price information for 'Dreams & Nightmares Case' in USD for the CS2 app.
# see more in examples.py
print(
scraper.market_scraper(
'Dreams & Nightmares Case',
Expand All @@ -131,10 +135,58 @@ print(
```
#### Output json data:
```json
{
"success": true,
"lowest_price": "$2.19",
"volume": "112,393",
"median_price": "$2.16",
"game_name": "CS2",
"currency_name": "USD",
"item_name": "Dreams & Nightmares Case"
}
```

### ⚡ Asynchronous usage

#### see more in examples.py
```python
async def main():
items = [
('Dreams & Nightmares Case', data.steam_data.Apps.CS2.value, data.steam_data.Currency.USD.value),
('Mann Co. Supply Crate Key', data.steam_data.Apps.TEAM_FORTRESS_2.value, data.steam_data.Currency.EUR.value),
...
]

tasks = [
src.scraper.async_.market_scraper_async(name, app_id, currency)
for name, app_id, currency in items
]
results = await asyncio.gather(*tasks)
for result in results:
print(result)

if __name__ == '__main__':
asyncio.run(main())
```

#### Output json data:
```json
{
"success": true,
"lowest_price": "$2.19",
"volume": "112,393",
"median_price": "$2.16",
"game_name": "CS2",
"currency_name": "USD",
"item_name": "Dreams & Nightmares Case"
}
{
"success": true,
"lowest_price": "$1.90",
"volume": "77,555",
"median_price": "$1.90"
"lowest_price": "2,01€",
"volume": "18,776",
"median_price": "2,03€",
"game_name": "TEAM_FORTRESS_2",
"currency_name": "EUR",
"item_name": "Mann Co. Supply Crate Key"
}
```
Empty file added data/__init__.py
Empty file.
File renamed without changes.
74 changes: 46 additions & 28 deletions examples.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,57 @@
import data
import scraper
import asyncio

if __name__ == '__main__':
print(
scraper.market_scraper(
import data.steam_data
import src.scraper.async_
import src.scraper.sync

# sync
print(
src.scraper.sync.market_scraper_sync(
'Dreams & Nightmares Case',
data.steam_data.Apps.CS2.value,
data.steam_data.Currency.USD.value,
),
)


# async
async def main():
items = [
(
'Dreams & Nightmares Case',
data.Apps.CS2.value,
data.Currency.USD.value,
data.steam_data.Apps.CS2.value,
data.steam_data.Currency.USD.value,
),
)
print(
scraper.market_scraper(
(
'Mann Co. Supply Crate Key',
data.Apps.TEAM_FORTRESS_2.value,
data.Currency.EUR.value,
data.steam_data.Apps.TEAM_FORTRESS_2.value,
data.steam_data.Currency.EUR.value,
),
)
print(
scraper.market_scraper(
(
'Doomsday Hoodie',
data.Apps.PUBG.value,
data.Currency.GBP.value,
data.steam_data.Apps.PUBG.value,
data.steam_data.Currency.GBP.value,
),
)
print(
scraper.market_scraper(
(
'AWP | Neo-Noir (Factory New)',
data.Apps.CS2.value,
data.Currency.USD.value,
data.steam_data.Apps.CS2.value,
data.steam_data.Currency.USD.value,
),
)
print(
scraper.market_scraper(
(
'Snowcamo Jacket',
data.Apps.RUST.value,
data.Currency.CHF.value,
data.steam_data.Apps.RUST.value,
data.steam_data.Currency.CHF.value,
),
)
]

tasks = [
src.scraper.async_.market_scraper_async(name, app_id, currency)
for name, app_id, currency in items
]
results = await asyncio.gather(*tasks)
for result in results:
print(result)


if __name__ == '__main__':
asyncio.run(main())
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ruff==0.11.6
aiohttp==3.11.18
ruff==0.11.10
Empty file added src/__init__.py
Empty file.
Empty file added src/scraper/__init__.py
Empty file.
79 changes: 79 additions & 0 deletions src/scraper/async_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import asyncio
import json

import aiohttp

import data.steam_data
import src.scraper.common


async def fetch_price(
session: aiohttp.ClientSession,
item_name: str,
app_id: int,
currency: int,
) -> str:
"""
A request is sent asynchronously to the Steam Market and a formatted
JSON response or error text is returned.
"""
encoded = src.scraper.common.encode_item_name(item_name)
url = (
f'{src.scraper.common.BASE_URL}'
f'appid={app_id}'
f'&currency={currency}'
f'&market_hash_name={encoded}'
)

try:
async with session.get(url, timeout=5) as response:
text = await response.text()
parsed = json.loads(text)

return src.scraper.common.format_response(
item_name,
app_id,
currency,
parsed,
)

except aiohttp.ClientResponseError as e:
return f'Server error: {e.status}'
except aiohttp.ClientConnectionError:
return 'Network error. Please check your internet connection.'
except asyncio.TimeoutError:
return 'Timeout error.'
except json.JSONDecodeError:
return 'Error decoding JSON response from server.'


async def market_scraper_async(
item_name: str,
app_id: int,
currency: int = data.steam_data.Currency.USD.value,
) -> str:
"""
Asynchronously fetch the market price for a given Steam item.

This coroutine validates the input parameters, opens an HTTP session,
and delegates to the `fetch_price` helper to retrieve live pricing data
from the Steam market.

Parameters:
item_name (str): The exact name of the Steam marketplace item.
app_id (int): The Steam application ID where the item is listed.
currency (int, optional): The currency code for price conversion.
Defaults to USD if not provided.

Returns:
str: A formatted result, which may be a JSON string
(via `format_response`) or an error message if the fetch fails.

Raises:
ValueError: If any of `item_name`, `app_id`, or `currency` is invalid.
aiohttp.ClientError: If the HTTP request to the Steam API fails.
"""

src.scraper.common.validate_parameters(item_name, app_id, currency)
async with aiohttp.ClientSession() as session:
return await fetch_price(session, item_name, app_id, currency)
Loading