|
|
@ -1,9 +1,11 @@
|
|
|
|
import os, argparse, sys, re
|
|
|
|
import os, argparse, sys, re
|
|
|
|
from mwclient import Site
|
|
|
|
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'
|
|
|
|
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)
|
|
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
|
|
# TODO: Add example of command to description
|
|
|
|
# TODO: Add example of command to description
|
|
|
|
p.add_argument('--host', default='hub.xpub.nl/sandbox', help='wiki host')
|
|
|
|
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"')
|
|
|
|
'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.'
|
|
|
|
p.add_argument('--creator', required=True, action='append', help='Metadata **Creator** value(s) of publication.'
|
|
|
|
'Multiple values should be SEPARATED BY COMMA')
|
|
|
|
'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()
|
|
|
|
args = p.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
# login
|
|
|
|
# login
|
|
|
@ -42,10 +45,13 @@ elif len(list(site.ask(f'[[Title::{args.title}]]'))) > 0:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO os.listdir(args.dir) ORDER!
|
|
|
|
# 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 = reorder_imgs(dir=args.dir, dry=args.dry)
|
|
|
|
lsimgs.sort()
|
|
|
|
|
|
|
|
print('lsimgs:', lsimgs)
|
|
|
|
print('lsimgs:', lsimgs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sys.exit() ## STOP HERE
|
|
|
|
|
|
|
|
|
|
|
|
# TODO PartOf from os.listdir(args.dir) that fit on to condition
|
|
|
|
# TODO PartOf from os.listdir(args.dir) that fit on to condition
|
|
|
|
# TODO Part base on os.lisdir order!
|
|
|
|
# TODO Part base on os.lisdir order!
|
|
|
|
|
|
|
|
|
|
|
@ -64,7 +70,7 @@ if args.dry == True:
|
|
|
|
print(args)
|
|
|
|
print(args)
|
|
|
|
sys.exit()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
|
|
for n _file in enumerate(lsimgs):
|
|
|
|
for n, _file in enumerate(lsimgs):
|
|
|
|
print_colormsg(_file, level='ok')
|
|
|
|
print_colormsg(_file, level='ok')
|
|
|
|
page = site.pages[_file]
|
|
|
|
page = site.pages[_file]
|
|
|
|
if page.exists:
|
|
|
|
if page.exists:
|
|
|
@ -72,8 +78,6 @@ for n _file in enumerate(lsimgs):
|
|
|
|
print_colormsg(
|
|
|
|
print_colormsg(
|
|
|
|
f'Already exists in {url} Will be uploaded as new version',
|
|
|
|
f'Already exists in {url} Will be uploaded as new version',
|
|
|
|
level='warning')
|
|
|
|
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')
|
|
|
|
print('The upload process wont proceed. Please upload all images in folder by hand')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
with open(filename, 'rb') as _file:
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|