diff options
| author | Tao Lin <831611+mirguest@users.noreply.github.com> | 2020-07-23 05:54:36 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-22 14:54:36 -0700 |
| commit | c25998bf12c5dd0e0866886fed54a95a2153e48b (patch) | |
| tree | 7924c96d6545160ae6a7312bac714c23e439a823 | |
| parent | 1901be9d17b1b27adc95982b84fe8aa43d3c123e (diff) | |
| download | wikiget-c25998bf12c5dd0e0866886fed54a95a2153e48b.tar.gz wikiget-c25998bf12c5dd0e0866886fed54a95a2153e48b.zip | |
Support private mediawiki (#1)
* add relative path support.
* add username and password support.
Co-authored-by: Cody Logan <clpo13@gmail.com>
| -rw-r--r-- | wikiget/__init__.py | 1 | ||||
| -rw-r--r-- | wikiget/dl.py | 13 | ||||
| -rw-r--r-- | wikiget/wikiget.py | 11 |
3 files changed, 19 insertions, 6 deletions
diff --git a/wikiget/__init__.py b/wikiget/__init__.py index 0225ec5..cb4f89f 100644 --- a/wikiget/__init__.py +++ b/wikiget/__init__.py @@ -22,5 +22,6 @@ from .version import __version__ # set some global constants BLOCKSIZE = 65536 DEFAULT_SITE = 'commons.wikimedia.org' +DEFAULT_PATH = '/w/' USER_AGENT = 'wikiget/{} (https://github.com/clpo13/wikiget) ' \ 'mwclient/{}'.format(__version__, mwclient_version) diff --git a/wikiget/dl.py b/wikiget/dl.py index 972058d..c7e593f 100644 --- a/wikiget/dl.py +++ b/wikiget/dl.py @@ -45,10 +45,10 @@ def download(dl, args): site_match = valid_site(site_name) # check for valid site parameter - if not site_match: - print('Only Wikimedia sites (wikipedia.org and wikimedia.org) ' - 'are currently supported.') - sys.exit(1) + # if not site_match: + # print('Only Wikimedia sites (wikipedia.org and wikimedia.org) ' + # 'are currently supported.') + # sys.exit(1) # check if this is a valid file if file_match and file_match.group(1): @@ -68,7 +68,10 @@ def download(dl, args): # connect to site and identify ourselves try: - site = Site(site_name, clients_useragent=USER_AGENT) + print("Site name: {}".format(site_name)) + site = Site(site_name, path=args.path, clients_useragent=USER_AGENT) + if args.username and args.password: + site.login(args.username, args.password) except ConnectionError: # usually this means there is no such site, # or there's no network connection diff --git a/wikiget/wikiget.py b/wikiget/wikiget.py index ab2ace0..c991faf 100644 --- a/wikiget/wikiget.py +++ b/wikiget/wikiget.py @@ -19,7 +19,7 @@ import argparse import logging import sys -from . import DEFAULT_SITE, __version__ +from . import DEFAULT_SITE, DEFAULT_PATH, __version__ from .dl import download @@ -63,6 +63,15 @@ def main(): parser.add_argument('-s', '--site', default=DEFAULT_SITE, help='MediaWiki site to download from ' '(default: %(default)s)') + parser.add_argument('-p', '--path', default=DEFAULT_PATH, + help='MediaWiki site path to download from ' + '(default: %(default)s)') + parser.add_argument('--username', default="", + help='MediaWiki site username ' + '(default: %(default)s)') + parser.add_argument('--password', default="", + help='MediaWiki site password ' + '(default: %(default)s)') output_options = parser.add_mutually_exclusive_group() output_options.add_argument('-o', '--output', help='write download to OUTPUT') |
