nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 42 lines 1.1 kB view raw
1import subprocess 2 3from html.parser import HTMLParser 4from os.path import abspath, dirname 5from urllib.request import urlopen 6 7class WiktionaryLatestVersionParser(HTMLParser): 8 def __init__(self, current_version, *args, **kwargs): 9 self.latest_version = current_version 10 super().__init__(*args, **kwargs) 11 12 13 def handle_starttag(self, tag, attrs): 14 if tag != 'a': 15 return 16 17 href = dict(attrs)['href'][0:-1] 18 if href == 'latest': 19 return 20 21 self.latest_version = max(self.latest_version, href) 22 23 24def nix_prefetch_url(url, algo='sha256'): 25 """Prefetches the content of the given URL.""" 26 print(f'nix-prefetch-url {url}') 27 out = subprocess.check_output(['nix-prefetch-url', '--type', algo, url]) 28 return out.rstrip() 29 30 31current_version = subprocess.check_output([ 32 'nix', 'eval', '--raw', 33 '-f', dirname(abspath(__file__)) + '/../../../..', 34 'dictdDBs.wiktionary.version', 35]) 36 37parser = WiktionaryLatestVersionParser(current_version) 38 39with urlopen('https://dumps.wikimedia.org/enwiktionary/') as resp: 40 parser.feed(resp.read()) 41 42print(parser.latest_version)