uploading image with smw info box

docker
Castro0o 5 years ago
parent c4d546b6b1
commit 1e109546b6

@ -153,18 +153,3 @@ def reorder_imgs(dir, dry):
if dry == False: if dry == False:
os.replace(src_img, dst_img) os.replace(src_img, dst_img)
return listimgs(dir) # update list w/ renamed imgs return listimgs(dir) # update list w/ renamed imgs
smw_propval_template = '''
\{\{ImageMetadata
|Title={title}
|Date={date}
|Part={part}
|Partof={partof}
|Creator={creator}
|Organization={organization}
|Format={format}
|Event={event}
|Topic={topic}
\}\}
[[Template:ImageMetadata]]
'''

@ -0,0 +1,12 @@
{{ '{{' }}ImageMetadata
|Title={{ title }}
|Date={{ date }}
|Part={{ part }}
|Partof={{ partof }}
|Creator={{ creator }}
|Organization={{ organization }}
|Format={{ format }}
|Event={{ event }}
|Topic={{ topic }}
{{ '}}' }}
[[Template:ImageMetadata]]

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

Loading…
Cancel
Save