49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
'''Data exporter from BRE used mainly for automation'''
|
|
import os
|
|
import sys
|
|
import logging
|
|
from datetime import datetime
|
|
|
|
import portal as bre
|
|
|
|
def _extract_password(token: str) -> str:
|
|
return bre.decrypt(token, '3EJalkimf91-muM') # hard-coded password meant to obfuscate master password on call
|
|
|
|
if __name__ == '__main__':
|
|
import argparse
|
|
if not os.path.exists("logs/"):
|
|
os.makedirs("logs/")
|
|
logging.basicConfig(
|
|
filename=datetime.now().strftime('logs/%Y%m%d_%H%M export.log'), encoding='utf-8', level=logging.INFO,
|
|
format='%(asctime)s %(levelname)s %(funcName)s: %(message)s',
|
|
datefmt='%Y%m%d_%H:%M:%S'
|
|
)
|
|
logging.getLogger().addHandler(logging.StreamHandler())
|
|
|
|
parser = argparse.ArgumentParser(description='BRE automation parameters')
|
|
parser.add_argument('filename')
|
|
parser.add_argument('config', help='Configuration INI file')
|
|
|
|
args = parser.parse_args(sys.argv)
|
|
|
|
config = bre.read_config(args.config)
|
|
config['AppData']['Password'] = _extract_password(config['AppData']['AccessToken'])
|
|
|
|
portal = bre.PortalAPI(config)
|
|
if not portal.validate(config['AppData']['Password']):
|
|
sys.exit(-1)
|
|
if not portal.set_output_tasks(config['AppData']['Output']):
|
|
sys.exit(-1)
|
|
if config['AppData']['ScanContent'] and not portal.set_output_content(config['AppData']['OutputContent']):
|
|
sys.exit(-1)
|
|
|
|
try:
|
|
exit_code: int = portal.export_tasks()
|
|
except SystemExit as e:
|
|
exit_code = e
|
|
except: # pylint: disable=bare-except
|
|
logging.exception("message")
|
|
raise
|
|
del portal
|
|
sys.exit(exit_code)
|