Exemple #1
0

def main():
    """Main App Logic"""
    json_data = tcex.playbook.read(args.json_data)

    try:
        json.loads(json_data)
    except Exception as e:
        err = 'JSON data was not properly formatted ({}).'.format(e)
        tcex.log.error(err)
        tcex.message_tc(err)
        tcex.playbook.exit(1)

    # create output
    tcex.log.info('JSON data: {}'.format(json_data))
    tcex.playbook.create_output('json.data', json_data)

    tcex.message_tc('JSON data has been created.')
    tcex.exit()


if __name__ == '__main__':
    try:
        main()
    except Exception as e:
        main_err = 'Generic Error.  See logs for more details ({}).'.format(e)
        tcex.log.error(traceback.format_exc())
        tcex.message_tc(main_err)
        tcex.playbook.exit(1)
    """Parse the incoming PDF contents as a PDF."""
    # handle the incoming arguments
    args = parse_arguments()

    # read the pdf_content from the tcex playbook to get the actual value of the pdf content
    pdf_content = tcex.playbook.read(args.pdf_content)

    # get the text from the PDF contents
    text = convert_pdf_to_txt(pdf_content)

    # output the text as a variable for downstream apps
    tcex.playbook.create_output('pdf_reader.text', text)

    # hasta luego
    tcex.exit()


if __name__ == "__main__":
    # initialize a TcEx instance
    tcex = TcEx()
    try:
        # start the app
        main()
    except SystemExit:
        pass
    except:  # if there are any strange errors, log it to the logging in the UI
        err = 'Generic Error. See logs for more details.'
        tcex.log.error(traceback.format_exc())
        tcex.message_tc(err)
        tcex.playbook.exit(1)