<commit_before>import demistomock as demisto
from CommonServerPython import *
from CommonServerUserPython import *
import base64
from sane_doc_reports.main import run

try:
    sane_json_b64 = demisto.args().get('sane_docx_report_base64', '').encode(
        "utf-8")
    with open('sane.json', 'wb') as f:
        f.write(base64.b64decode(sane_json_b64))

    run('sane.json', 'out.docx')

    with open('out.docx', 'rb') as f:
        encoded = base64.b64encode(f.read()).decode("utf-8", "ignore")
        return_outputs(readable_output='Successfully generated docx',
                       outputs={}, raw_response={'data': encoded})
except Exception as e:
    return_error(f'[SaneDocReports Automation Error] - {str(e)}')<commit_msg>Constant file path, remove file after use and better error message<commit_after>import os
import demistomock as demisto
from CommonServerPython import *
from CommonServerUserPython import *
import base64
from sane_doc_reports.main import run


OUTPUT_FILE_PATH = 'out.docx'
try:
    sane_json_b64 = demisto.args().get('sane_docx_report_base64', '').encode(
        "utf-8")
    with open('sane.json', 'wb') as f:
        f.write(base64.b64decode(sane_json_b64))

    run('sane.json', OUTPUT_FILE_PATH)

    with open(OUTPUT_FILE_PATH, 'rb') as f:
        encoded = base64.b64encode(f.read()).decode("utf-8", "ignore")

    os.remove(OUTPUT_FILE_PATH)
    return_outputs(readable_output='Successfully generated docx',
                   outputs={}, raw_response={'data': encoded})
except Exception as e:
    err = repr(e)
    return_error(f'[SaneDocReports Automation Error] - {err}')
{'fraction_non_alphanumeric': 0.12777777777777777, 'fraction_numerical': 0.022222222222222223, 'mean_word_length': 4.065625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3089837', 'n_tokens_mistral': 565, 'n_tokens_neox': 531, 'n_words': 118}