|
|
|
@ -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 )
|
|
|
|
|