1st img upload script
parent
abc6b0da97
commit
dcec809e99
@ -0,0 +1,58 @@
|
||||
import os, argparse
|
||||
from mwclient import Site
|
||||
|
||||
|
||||
p = argparse.ArgumentParser(description="Upload files from a folder",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
p.add_argument("--host", metavar='', default="hub.xpub.nl/sandbox", help='wiki host')
|
||||
p.add_argument("--path", metavar='', default="/itchwiki/", help="Wiki path. Should end with /")
|
||||
p.add_argument("--scheme", default="https", help="http or https")
|
||||
|
||||
args = p.parse_args()
|
||||
|
||||
site = Site(host=args.host, path=args.path, scheme=args.scheme)
|
||||
|
||||
wd = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # parent working directory
|
||||
|
||||
with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd
|
||||
loginlines = login.read()
|
||||
user, pwd = loginlines.split('\n')
|
||||
site.login(username=user, password=pwd) # login to wiki
|
||||
|
||||
site = Site(host=args.host, path=args.path)
|
||||
|
||||
# login
|
||||
with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd
|
||||
loginlines = login.read()
|
||||
user, pwd = loginlines.split('\n')
|
||||
site.login(username=user, password=pwd) # login to wiki
|
||||
|
||||
# todo: add arguments: title date creator imgsdir (full path)
|
||||
# todo: check title existance, chech date format
|
||||
# todo: loop though images in folder (.jpg, .jpeg, .png) ensuring correct order 1 before 11
|
||||
|
||||
|
||||
smw_prop_val = '''{{ImageMetadata
|
||||
|Title={title}
|
||||
|Date={date}
|
||||
|Part={part}
|
||||
|Partof={partof}
|
||||
|Creator={creator}
|
||||
}}
|
||||
[[Template:ImageMetadata]]
|
||||
'''
|
||||
|
||||
img_smw_prop_val = smw_prop_val.format(title='cat from hell', date='2020/02/13', part='1', partof='1', creator='test')
|
||||
print(img_smw_prop_val)
|
||||
|
||||
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:
|
||||
site.upload(file=_file, filename=filename, description='img_smw_prop_val', ignore=True)
|
||||
|
Loading…
Reference in New Issue