首页 > 后端开发 > Python教程 > 为欧洲翻新蒸汽甲板构建可用性检查器

为欧洲翻新蒸汽甲板构建可用性检查器

Mary-Kate Olsen
发布: 2025-01-24 02:14:14
原创
270 人浏览过

Building an Availability Checker for Refurbished Steam Decks in Europe

由于库存波动,在欧洲获得翻新的 Steam Deck 可能具有挑战性。这个基于 Python 的可用性检查器可自动执行该过程,并在出现翻新设备时提供实时通知。 这篇文章详细介绍了该项目的技术实现并鼓励社区贡献。

项目概览

此 Python 脚本监视 Steam 商店在欧洲是否有翻新的 Steam Deck。 利用 ntfy 通知服务,当库存有货时,它会立即提醒用户。 该项目展示了如何使用现成的 Python 库和 API 来高效解决问题。

功能

脚本运行如下:

  1. 它定期查询 Steam API 以获取库存更新。
  2. 检测到可用库存后,它会发送 ntfy 通知。
  3. 通过调度脚本(例如使用 cron)来实现持续监控。

核心逻辑:

<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>
登录后复制

执行

  1. 安装最新的 Python 版本。不需要额外的模块。
  2. ntfy_url 替换为您的个人 ntfy URL(从 ntfy 网站获取一个)。 建议使用ntfy移动应用程序进行通知。
  3. 对于 Windows Server 用户,请将 ntfy.shapi.steampowered.com 添加到 Internet Explorer 设置中的受信任站点。

结论

该项目强调了简洁的 Python 脚本在实际任务中的强大功能。它是 API 交互、通知和 Python 自动化的宝贵学习资源。 完整代码在GitHub上,欢迎贡献和定制。

以上是为欧洲翻新蒸汽甲板构建可用性检查器的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板