uploading image with smw info box

pull/1/head
Castro0o 5 years ago
parent c4d546b6b1
commit 1e109546b6

@ -153,18 +153,3 @@ def reorder_imgs(dir, dry):
if dry == False:
os.replace(src_img, dst_img)
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
from mwclient import Site
from jinja2 import Template
from functions import (print_colormsg,
reorder_imgs,
smw_propval_template)
reorder_imgs)
p = argparse.ArgumentParser(description='Upload files from a directory, with metadata values to the wiki.\n'
'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')
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)
dirname = os.path.split(args.dir)[-1].replace(' ', '_')
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',
level='warning')
else:
img_smw_prop_val = smw_propval_template.format(
img_smw_prop_val = smw_propval_template.render(
title=args.title,
date=args.date,
part=n + 1,

Loading…
Cancel
Save