diff --git a/setup.py b/setup.py index 8efb9a7..b721491 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="legunto", - version="0.0.1", + version="0.1.1", description="Fetch MediaWiki Scribunto modules from wikis", long_description=long_description, long_description_content_type="text/markdown", diff --git a/src/legunto/__init__.py b/src/legunto/__init__.py index 0d0d10f..a68845e 100644 --- a/src/legunto/__init__.py +++ b/src/legunto/__init__.py @@ -6,6 +6,7 @@ import os import pathlib import sys +import typing def print_help_massage() -> None: @@ -29,15 +30,19 @@ def get_interwiki_map() -> hash: return iw_map -def fetch_module(url: str, module_name: str) -> hash: +def fetch_module(url: str, module_name: str) -> typing.Union[hash, None]: if not module_name.startswith('Module:'): module_name = 'Module:'+module_name module = {} url = urlparse(url) - print(f'Fetching "{module_name}" from {url.netloc} ...', end='') site = mwclient.Site(url.netloc, scheme=url.scheme) + if not site.pages[module_name].exists: + logging.warning( \ + f'"{module_name}" is not exist on {url.netloc} ... Skip') + return + print(f'Fetching "{module_name}" from {url.netloc} ...', end='') result = site.api('query', titles=module_name, prop='info', utf8="1") result = list(result['query']['pages'].values())[0] @@ -90,6 +95,8 @@ def install_dependencies() -> None: # TODO read lock file and compare revids to skip fetching module = fetch_module(interwiki[wiki], page) + if not module: + continue lock['modules'][dep] = { 'pageid': module['pageid'], 'revid': module['revid'],