upload working. But template formating nees % notation

docker
Castro0o 5 years ago
parent c996cb98b6
commit 29f569346e

@ -155,7 +155,7 @@ def reorder_imgs(dir, dry):
return listimgs(dir) # update list w/ renamed imgs return listimgs(dir) # update list w/ renamed imgs
smw_propval_template = ''' smw_propval_template = '''
{{ImageMetadata \{\{ImageMetadata
|Title={title} |Title={title}
|Date={date} |Date={date}
|Part={part} |Part={part}
@ -165,6 +165,6 @@ smw_propval_template = '''
|Format={format} |Format={format}
|Event={event} |Event={event}
|Topic={topic} |Topic={topic}
}} \}\}
[[Template:ImageMetadata]] [[Template:ImageMetadata]]
''' '''

@ -64,8 +64,6 @@ 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()
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
@ -87,31 +85,23 @@ for n, _file in enumerate(lsimgs):
date=args.date, date=args.date,
part=n + 1, part=n + 1,
partof=len(lsimgs), partof=len(lsimgs),
creator=(',').join(args.creator[1:]), creator=(', ').join(args.creator[1:]),
organization=(',').join(args.organization[1:]), organization=(', ').join(args.organization[1:]),
format=(',').join(args.format[1:]), format=(', ').join(args.format[1:]),
event=(',').join(args.event[1:]), event=(', ').join(args.event[1:]),
topic=(',').join(args.topic[1:]) topic=(', ').join(args.topic[1:])
) )
print(img_smw_prop_val) _file_path = os.path.join(args.dir, _file)
print(_file_path)
if args.dry == True: if not args.dry:
print(args) with open(_file_path, 'rb') as _f:
sys.exit() site.upload(file=_file_path,
filename=pagename,
description=img_smw_prop_val,
ignore=True)
print(img_smw_prop_val)
print(f'https://{args.host}{args.path}index.php/File:{pagename}')
filename = 'cat2.jpg'
page = site.images[filename]
img_url = f'https://{args.host}{args.path}/index.php/File:{filename}'
if page.exists is True:
print(f'{filename} is already upload it, you can see it at {img_url}' )
print('The upload process wont proceed. Please upload all images in folder by hand')
else:
with open(filename, 'rb') as _file:
dirname = (os.path.split(dir)[-1])
site.upload(file=_file, filename=f'{dirname}_{filename}',
description='img_smw_prop_val', ignore=True)

Loading…
Cancel
Save