Skip to content

Commit

Permalink
Handle non exist page exception
Browse files Browse the repository at this point in the history
  • Loading branch information
lens0021 committed Jul 23, 2020
1 parent 606b0a9 commit 600e97d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 9 additions & 2 deletions src/legunto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import pathlib
import sys
import typing


def print_help_massage() -> None:
Expand All @@ -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]
Expand Down Expand Up @@ -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'],
Expand Down

0 comments on commit 600e97d

Please sign in to comment.