Home >Backend Development >Python Tutorial >Building an Availability Checker for Refurbished Steam Decks in Europe

Building an Availability Checker for Refurbished Steam Decks in Europe

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-24 02:14:14220browse

Building an Availability Checker for Refurbished Steam Decks in Europe

Securing a refurbished Steam Deck in Europe can be challenging due to fluctuating stock. This Python-based availability checker automates the process, providing real-time notifications when refurbished units appear. This post details the project's technical implementation and encourages community contributions.

Project Overview

This Python script monitors Steam's store for refurbished Steam Deck availability in Europe. Leveraging the ntfy notification service, it instantly alerts users when stock becomes available. The project showcases efficient problem-solving using readily available Python libraries and APIs.

Functionality

The script operates as follows:

  1. It periodically queries the Steam API for stock updates.
  2. Upon detecting available stock, it sends an ntfy notification.
  3. Continuous monitoring is achieved by scheduling the script (e.g., using cron).

Core Logic:

<code class="language-python">from urllib.request import urlopen

# Configure your ntfy URL
ntfy_url = "ntfy.sh/YOUR_NTFY_URL"

# Timeout to prevent script hang-ups
timeout = 8


def parse_availability(data: bytes) -> bool:
    parsed = " ".join(f"{c:02X}" for c in data)
    not_available = "08 00 10 00"
    return parsed != not_available


def is_available(id_: str) -> bool:
    url = (
        "api.steampowered.com/IPhysicalGoodsService/"
        "CheckInventoryAvailableByPackage/v1?origin="
        f"https://store.steampowered.com&input_protobuf_encoded={id_}"
    )
    with urlopen(f"https://{url}", timeout=timeout) as response:
        data = response.read()
    return parse_availability(data)


def notify(name: str) -> None:
    message = f"Refurbished {name} Steam Deck is available!"
    print(message)
    with urlopen(f"https://{ntfy_url}", data=str.encode(message), timeout=timeout):
        pass


if __name__ == "__main__":
    # Uncomment for notification testing
    # notify("TEST")

    # Refurbished 64GB (European region, tested in Poland)
    if is_available("COGVNxICUEw="):
        notify("64GB")</code>

Execution

  1. Install a recent Python version. No additional modules are needed.
  2. Replace ntfy_url with your personal ntfy URL (obtain one from the ntfy website). The ntfy mobile app is recommended for notifications.
  3. For Windows Server users, add ntfy.sh and api.steampowered.com to your trusted sites in Internet Explorer settings.

Conclusion

This project highlights the power of concise Python scripts for practical tasks. It serves as a valuable learning resource for API interaction, notifications, and Python automation. The complete code is available on GitHub, welcoming contributions and customization.

The above is the detailed content of Building an Availability Checker for Refurbished Steam Decks in Europe. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn