|
|
@ -1,8 +1,8 @@
|
|
|
|
import os, argparse, sys, re
|
|
|
|
import os, argparse, sys, re
|
|
|
|
from mwclient import Site
|
|
|
|
from mwclient import Site
|
|
|
|
|
|
|
|
from jinja2 import Template
|
|
|
|
from functions import (print_colormsg,
|
|
|
|
from functions import (print_colormsg,
|
|
|
|
reorder_imgs,
|
|
|
|
reorder_imgs)
|
|
|
|
smw_propval_template)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 VALUES CONTAINING '
|
|
|
|
'Note that any VALUES CONTAINING '
|
|
|
@ -64,6 +64,10 @@ 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')
|
|
|
|
print_colormsg(f'Error: --title "{args.title}" already exists in wiki. Provide a different one', level='fail')
|
|
|
|
sys.exit()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# read template file
|
|
|
|
|
|
|
|
with open(os.path.join(wd, 'templates/smw_infobox_template.jinja')) as tmplt:
|
|
|
|
|
|
|
|
smw_propval_template = Template(tmplt.read())
|
|
|
|
|
|
|
|
|
|
|
|
lsimgs = reorder_imgs(dir=args.dir, dry=args.dry)
|
|
|
|
lsimgs = reorder_imgs(dir=args.dir, dry=args.dry)
|
|
|
|
dirname = os.path.split(args.dir)[-1].replace(' ', '_')
|
|
|
|
dirname = os.path.split(args.dir)[-1].replace(' ', '_')
|
|
|
|
dirname = re.sub(r'[\W]', '', dirname) #remove non letters or digits
|
|
|
|
dirname = re.sub(r'[\W]', '', dirname) #remove non letters or digits
|
|
|
@ -80,7 +84,7 @@ for n, _file in enumerate(lsimgs):
|
|
|
|
f'Already exists in {url} Will NOT be uploaded',
|
|
|
|
f'Already exists in {url} Will NOT be uploaded',
|
|
|
|
level='warning')
|
|
|
|
level='warning')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
img_smw_prop_val = smw_propval_template.format(
|
|
|
|
img_smw_prop_val = smw_propval_template.render(
|
|
|
|
title=args.title,
|
|
|
|
title=args.title,
|
|
|
|
date=args.date,
|
|
|
|
date=args.date,
|
|
|
|
part=n + 1,
|
|
|
|
part=n + 1,
|
|
|
|