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
):
17 href
= dict(attrs
)['href'][0:-1]
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
])
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
)