2021-02-11 16:43:36 +00:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from html.parser import HTMLParser
|
|
|
|
from os.path import abspath, dirname
|
|
|
|
from urllib.request import urlopen
|
|
|
|
|
|
|
|
class WiktionaryLatestVersionParser(HTMLParser):
|
|
|
|
def __init__(self, current_version, *args, **kwargs):
|
|
|
|
self.latest_version = current_version
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def handle_starttag(self, tag, attrs):
|
|
|
|
if tag != 'a':
|
|
|
|
return
|
|
|
|
|
|
|
|
href = dict(attrs)['href'][0:-1]
|
|
|
|
if href == 'latest':
|
|
|
|
return
|
|
|
|
|
|
|
|
self.latest_version = max(self.latest_version, href)
|
|
|
|
|
|
|
|
|
|
|
|
def nix_prefetch_url(url, algo='sha256'):
|
|
|
|
"""Prefetches the content of the given URL."""
|
|
|
|
print(f'nix-prefetch-url {url}')
|
|
|
|
out = subprocess.check_output(['nix-prefetch-url', '--type', algo, url])
|
2023-01-09 20:35:23 +00:00
|
|
|
return out.rstrip()
|
2021-02-11 16:43:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
current_version = subprocess.check_output([
|
|
|
|
'nix', 'eval', '--raw',
|
|
|
|
'-f', dirname(abspath(__file__)) + '/../../../..',
|
|
|
|
'dictdDBs.wiktionary.version',
|
2023-01-09 20:35:23 +00:00
|
|
|
])
|
2021-02-11 16:43:36 +00:00
|
|
|
|
|
|
|
parser = WiktionaryLatestVersionParser(current_version)
|
|
|
|
|
|
|
|
with urlopen('https://dumps.wikimedia.org/enwiktionary/') as resp:
|
2023-01-09 20:35:23 +00:00
|
|
|
parser.feed(resp.read())
|
2021-02-11 16:43:36 +00:00
|
|
|
|
|
|
|
print(parser.latest_version)
|