Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at github-to-sqlite-beautifulsoup4 41 lines 1.4 kB view raw
1#!/usr/bin/env nix-shell 2#!nix-shell -i python3 -p python3 python3.pkgs.packaging python3.pkgs.beautifulsoup4 python3.pkgs.requests 3# mirrored in ./default.nix 4from packaging import version 5from bs4 import BeautifulSoup 6import re, requests, json 7import os, sys 8from pathlib import Path 9 10URL = "https://downloads.asterisk.org/pub/telephony/asterisk/" 11 12page = requests.get(URL) 13changelog = re.compile("^ChangeLog-\d+\.\d+\.\d+\.md$") 14changelogs = [a.get_text() for a in BeautifulSoup(page.text, 'html.parser').find_all('a') if changelog.match(a.get_text())] 15major_versions = {} 16for changelog in changelogs: 17 v = version.parse(changelog.removeprefix("ChangeLog-").removesuffix(".md")) 18 major_versions.setdefault(v.major, []).append(v) 19 20out = {} 21for mv in major_versions.keys(): 22 v = max(major_versions[mv]) 23 sha = requests.get(f"{URL}/asterisk-{v}.sha256").text.split()[0] 24 out["asterisk_" + str(mv)] = { 25 "version": str(v), 26 "sha256": sha 27 } 28 29versions_path = Path(sys.argv[0]).parent / "versions.json" 30 31try: 32 with open(versions_path, "r") as in_file: 33 in_data = json.loads(in_file.read()) 34 for v in in_data.keys(): 35 print(v + ":", in_data[v]["version"], "->", out[v]["version"]) 36except: 37 # nice to have for the PR, not a requirement 38 pass 39 40with open(versions_path, "w") as out_file: 41 out_file.write(json.dumps(out, sort_keys=True, indent=2) + "\n")