Merge pull request #330634 from r-ryantm/auto-update/circumflex
[NixPkgs.git] / pkgs / servers / dict / wiktionary / latest_version.py
blob1aa767851ceedd83a417b5afd714308183ab3b1b
1 import subprocess
3 from html.parser import HTMLParser
4 from os.path import abspath, dirname
5 from urllib.request import urlopen
7 class WiktionaryLatestVersionParser(HTMLParser):
8 def __init__(self, current_version, *args, **kwargs):
9 self.latest_version = current_version
10 super().__init__(*args, **kwargs)
13 def handle_starttag(self, tag, attrs):
14 if tag != 'a':
15 return
17 href = dict(attrs)['href'][0:-1]
18 if href == 'latest':
19 return
21 self.latest_version = max(self.latest_version, href)
24 def 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()
31 current_version = subprocess.check_output([
32 'nix', 'eval', '--raw',
33 '-f', dirname(abspath(__file__)) + '/../../../..',
34 'dictdDBs.wiktionary.version',
37 parser = WiktionaryLatestVersionParser(current_version)
39 with urlopen('https://dumps.wikimedia.org/enwiktionary/') as resp:
40 parser.feed(resp.read())
42 print(parser.latest_version)