From f55323f854708f03cf9becfd71982c896a0bbd36 Mon Sep 17 00:00:00 2001 From: Castro0o Date: Wed, 15 Nov 2017 12:19:54 +0100 Subject: [PATCH] running on mwclient 0.8.6 (current version) --- README | 4 ++-- wiki-download.py | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README b/README index 015f490..2e82421 100644 --- a/README +++ b/README @@ -7,9 +7,9 @@ Install in Debian/Ubuntu: apt-get install pdftk imagemagick Install in Mac with brew (http://brew.sh/): brew install pdftk imagemagick -Python libraries: mwclient +Python libraries: mwclient (version 0.8.6) -Install in Debian/Ubuntu w/ pip: sudo pip install mwclient +Install in Debian/Ubuntu w/ pip: sudo pip install 'mwclient==0.8.6' ## Scripts diff --git a/wiki-download.py b/wiki-download.py index 41d7fe4..230025d 100755 --- a/wiki-download.py +++ b/wiki-download.py @@ -38,7 +38,7 @@ def mwsite(host, path): site = mwsite(args.host, args.path) -print site +#print site @@ -52,11 +52,10 @@ query= ('[[File:+]]'+ args.ask) for answer in site.ask(query): - - print answer + img_key = answer.keys()[0] + img_name = answer[img_key]['fulltext'] + img_page_url = answer[img_key]['fullurl'] img = image.Image(site, answer) - img_name = answer.title() - img_text = img.text() img_info = img.imageinfo # dict includes url and extensive metadata # FILE DOWNLOAD if 'url' in img_info.keys() and len(args.download) > 0: @@ -66,10 +65,15 @@ for answer in site.ask(query): os.makedirs(args.download) img_data = urllib2.urlopen( img_url ) - img_file = open('{}/{}'.format(args.download, img_name), 'wb') + img_file = open(u'{}/{}'.format(args.download, img_name), 'wb') img_file.write(img_data.read()) img_file.close() - print 'Saved to {}'.format(args.download + '/' + img_name) + global download_path + if args.download[-1] != '/': + download_path = args.download+'/' + else: + download_path = args.download + print u'Saved to {}'.format(download_path + img_name) if args.verbose: print 'File text:',img_text pprint.pprint( img_info )