print functions

pull/1/head
Castro0o 5 years ago
parent 1e109546b6
commit 9652ec2a2f

@ -96,13 +96,12 @@ def clean_dir(dirfullpath):
def print_colormsg(msg, level): def print_colormsg(msg, level):
if level == 'fail': if level == 'fail':
print(Colors.FAIL) color_cmd = Colors.FAIL
elif level == 'warning': elif level == 'warning':
print(Colors.WARNING) color_cmd = Colors.WARNING
elif level == 'ok': elif level == 'ok':
print(Colors.BLUE) color_cmd = Colors.BLUE
print(msg) print(color_cmd, msg, Colors.ENDC)
print(Colors.ENDC)
class Colors: class Colors:

@ -1,5 +1,6 @@
import os, argparse, sys, re import os, argparse, sys, re
from mwclient import Site from mwclient import (Site,
errors)
from jinja2 import Template from jinja2 import Template
from functions import (print_colormsg, from functions import (print_colormsg,
reorder_imgs) reorder_imgs)
@ -97,15 +98,19 @@ for n, _file in enumerate(lsimgs):
) )
_file_path = os.path.join(args.dir, _file) _file_path = os.path.join(args.dir, _file)
print(_file_path)
if not args.dry: if not args.dry:
pageurl = f'https://{args.host}{args.path}index.php/File:{pagename}'
with open(_file_path, 'rb') as _f: with open(_file_path, 'rb') as _f:
site.upload(file=_file_path, try:
filename=pagename, site.upload(file=_file_path,
description=img_smw_prop_val, filename=pagename,
ignore=True) description=img_smw_prop_val,
ignore=True)
print(img_smw_prop_val) print(img_smw_prop_val)
print(f'https://{args.host}{args.path}index.php/File:{pagename}') except errors.APIError as e:
print_colormsg(f'Error: {e.info}\n'
f'It will not be uploaded',
level='fail')
print(f'See image at {pageurl}')

Loading…
Cancel
Save