1#!/usr/bin/env nix-shell
2#!nix-shell --pure --keep NIX_PATH -i python3 -p git nix-update "python3.withPackages (ps: [ ps.beautifulsoup4 ps.requests ])"
3
4import sys
5import re
6import requests
7import subprocess
8from bs4 import BeautifulSoup
9
10VERSION_PATTERN = re.compile(r'^steam_(?P<ver>(\d+\.)+)tar.gz$')
11
12found_versions = []
13response = requests.get("https://repo.steampowered.com/steam/archive/stable/")
14soup = BeautifulSoup (response.text, "html.parser")
15for a in soup.find_all("a"):
16 href = a["href"]
17 if not href.endswith(".tar.gz"):
18 continue
19
20 match = VERSION_PATTERN.match(href)
21 if match is not None:
22 version = match.groupdict()["ver"][0:-1]
23 found_versions.append(version)
24
25if len(found_versions) == 0:
26 print("Failed to find available versions!", file=sys.stderr)
27 sys.exit(1)
28
29found_versions.sort()
30subprocess.run(["nix-update", "--version", found_versions[-1], "steam-unwrapped"])
31found_versions[0]