wip: list images

docker
Castro0o 5 years ago
parent 94f45441b6
commit 1c8ca7d045

@ -20,7 +20,7 @@ p.add_argument('--creator', required=True, action='append', help='Metadata **Cre
p.add_argument('--dir', required=True, help='Full path of the image directory, that you wish to upload')
args = p.parse_args()
# login
site = Site(host=args.host, path=args.path, scheme=args.scheme)
wd =os.path.dirname(os.path.abspath(__file__)) # parent working directory
@ -29,14 +29,7 @@ with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd
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
# metadata checks
if os.path.isdir(args.dir) is False:
print_colormsg(f'Error: --dir {args.dir} absolute path cannot be found', level='fail')
sys.exit()
@ -47,20 +40,16 @@ 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()
# TODO os.listdir(args.dir) ORDER!
lsimgs = [_file for _file in os.listdir(args.dir) if (os.path.splitext(_file)[-1]).lower() in
['.jpg', '.jpeg', '.png']]
lsimgs.sort()
print('lsimgs:', lsimgs)
# TODO PartOf from os.listdir(args.dir) that fit on to condition
# TODO Part base on os.lisdir order!
for _file in os.listdir(args.dir):
if (os.path.splitext(_file)[-1]).lower() not in ['.jpg', '.jpeg', '.png']:
print_colormsg(f'File: {_file} is not a .jpg .jpeg or .png hence will Not be upload', level='warning')
else:
print_colormsg(_file, level='ok')
if args.dry == True:
print(args)
sys.exit()
# todo creator value comma-seperated
smw_prop_val = '''{{ImageMetadata
|Title={title}
|Date={date}
@ -71,6 +60,25 @@ smw_prop_val = '''{{ImageMetadata
[[Template:ImageMetadata]]
'''
if args.dry == True:
print(args)
sys.exit()
for n _file in enumerate(lsimgs):
print_colormsg(_file, level='ok')
page = site.pages[_file]
if page.exists:
url = page.imageinfo['descriptionurl']
print_colormsg(
f'Already exists in {url} Will be uploaded as new version',
level='warning')
smw_prop_val.format(title=,
)
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)

Loading…
Cancel
Save