From 29f569346e8f15cc5547b1aaf11aa260b8dc841b Mon Sep 17 00:00:00 2001 From: Castro0o Date: Tue, 18 Feb 2020 23:26:53 +0100 Subject: [PATCH] upload working. But template formating nees % notation --- functions.py | 4 ++-- upload_imgs_dir.py | 40 +++++++++++++++------------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/functions.py b/functions.py index fcf23dd..59f0dd5 100644 --- a/functions.py +++ b/functions.py @@ -155,7 +155,7 @@ def reorder_imgs(dir, dry): return listimgs(dir) # update list w/ renamed imgs smw_propval_template = ''' -{{ImageMetadata +\{\{ImageMetadata |Title={title} |Date={date} |Part={part} @@ -165,6 +165,6 @@ smw_propval_template = ''' |Format={format} |Event={event} |Topic={topic} -}} +\}\} [[Template:ImageMetadata]] ''' diff --git a/upload_imgs_dir.py b/upload_imgs_dir.py index e767508..2f0da3c 100644 --- a/upload_imgs_dir.py +++ b/upload_imgs_dir.py @@ -64,8 +64,6 @@ elif len(list(site.ask(f'[[Title::{args.title}]]'))) > 0: print_colormsg(f'Error: --title "{args.title}" already exists in wiki. Provide a different one', level='fail') sys.exit() - - lsimgs = reorder_imgs(dir=args.dir, dry=args.dry) dirname = os.path.split(args.dir)[-1].replace(' ', '_') dirname = re.sub(r'[\W]', '', dirname) #remove non letters or digits @@ -87,31 +85,23 @@ for n, _file in enumerate(lsimgs): date=args.date, part=n + 1, partof=len(lsimgs), - creator=(',').join(args.creator[1:]), - organization=(',').join(args.organization[1:]), - format=(',').join(args.format[1:]), - event=(',').join(args.event[1:]), - topic=(',').join(args.topic[1:]) + creator=(', ').join(args.creator[1:]), + organization=(', ').join(args.organization[1:]), + format=(', ').join(args.format[1:]), + event=(', ').join(args.event[1:]), + topic=(', ').join(args.topic[1:]) ) - print(img_smw_prop_val) - -if args.dry == True: - print(args) - sys.exit() - + _file_path = os.path.join(args.dir, _file) + print(_file_path) + if not args.dry: + with open(_file_path, 'rb') as _f: + site.upload(file=_file_path, + filename=pagename, + description=img_smw_prop_val, + ignore=True) + print(img_smw_prop_val) + print(f'https://{args.host}{args.path}index.php/File:{pagename}') -filename = 'cat2.jpg' -page = site.images[filename] -img_url = f'https://{args.host}{args.path}/index.php/File:{filename}' - -if page.exists is True: - print(f'{filename} is already upload it, you can see it at {img_url}' ) - print('The upload process wont proceed. Please upload all images in folder by hand') -else: - with open(filename, 'rb') as _file: - dirname = (os.path.split(dir)[-1]) - site.upload(file=_file, filename=f'{dirname}_{filename}', - description='img_smw_prop_val', ignore=True)