|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
import os, argparse, sys, re
|
|
|
|
|
from mwclient import Site
|
|
|
|
|
from functions import print_colormsg
|
|
|
|
|
from functions import (print_colormsg,
|
|
|
|
|
reorder_imgs)
|
|
|
|
|
|
|
|
|
|
p = argparse.ArgumentParser(description='Upload files from a directory, with metadata values to the wiki.\n'
|
|
|
|
|
'Note that any value containing spaces should be between quotation marks',
|
|
|
|
|
'Note that any VALUES CONTAINING '
|
|
|
|
|
'SPACES SHOULD BE BETWEEN QUOTATION MARKS',
|
|
|
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
|
|
|
# TODO: Add example of command to description
|
|
|
|
|
p.add_argument('--host', default='hub.xpub.nl/sandbox', help='wiki host')
|
|
|
|
@ -17,7 +19,8 @@ p.add_argument('--date', required=True, help='Metadata **Date** value of publica
|
|
|
|
|
'For dates without day or date use 01 ie. 1986 --date "1986/01/01" March 1985: --date "1984/05/01"')
|
|
|
|
|
p.add_argument('--creator', required=True, action='append', help='Metadata **Creator** value(s) of publication.'
|
|
|
|
|
'Multiple values should be SEPARATED BY COMMA')
|
|
|
|
|
p.add_argument('--dir', required=True, help='Full path of the image directory, that you wish to upload')
|
|
|
|
|
p.add_argument('--dir', required=True, help='Full path of the image directory, '
|
|
|
|
|
'that you wish to upload')
|
|
|
|
|
args = p.parse_args()
|
|
|
|
|
|
|
|
|
|
# login
|
|
|
|
@ -42,10 +45,13 @@ elif len(list(site.ask(f'[[Title::{args.title}]]'))) > 0:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO os.listdir(args.dir) ORDER!
|
|
|
|
|
lsimgs = [_file for _file in os.listdir(args.dir) if (os.path.splitext(_file)[-1]).lower() in
|
|
|
|
|
['.jpg', '.jpeg', '.png']]
|
|
|
|
|
lsimgs.sort()
|
|
|
|
|
|
|
|
|
|
lsimgs = reorder_imgs(dir=args.dir, dry=args.dry)
|
|
|
|
|
|
|
|
|
|
print('lsimgs:', lsimgs)
|
|
|
|
|
|
|
|
|
|
sys.exit() ## STOP HERE
|
|
|
|
|
|
|
|
|
|
# TODO PartOf from os.listdir(args.dir) that fit on to condition
|
|
|
|
|
# TODO Part base on os.lisdir order!
|
|
|
|
|
|
|
|
|
@ -64,7 +70,7 @@ if args.dry == True:
|
|
|
|
|
print(args)
|
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
for n _file in enumerate(lsimgs):
|
|
|
|
|
for n, _file in enumerate(lsimgs):
|
|
|
|
|
print_colormsg(_file, level='ok')
|
|
|
|
|
page = site.pages[_file]
|
|
|
|
|
if page.exists:
|
|
|
|
@ -72,8 +78,6 @@ for n _file in enumerate(lsimgs):
|
|
|
|
|
print_colormsg(
|
|
|
|
|
f'Already exists in {url} Will be uploaded as new version',
|
|
|
|
|
level='warning')
|
|
|
|
|
smw_prop_val.format(title=,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -91,5 +95,7 @@ if page.exists is True:
|
|
|
|
|
print('The upload process wont proceed. Please upload all images in folder by hand')
|
|
|
|
|
else:
|
|
|
|
|
with open(filename, 'rb') as _file:
|
|
|
|
|
site.upload(file=_file, filename=filename, description='img_smw_prop_val', ignore=True)
|
|
|
|
|
dirname = (os.path.split(dir)[-1])
|
|
|
|
|
site.upload(file=_file, filename=f'{dirname}_{filename}',
|
|
|
|
|
description='img_smw_prop_val', ignore=True)
|
|
|
|
|
|
|
|
|
|