#!/usr/bin/env python

# ================================================================
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# ================================================================

import sys
import json
import TE

TE.Net.setAppTokenFromEnvName("TX_ACCESS_TOKEN")

postParams = {
    "descriptor_id": "4036655176350945",  # ID of the descriptor to be updated
    "reactions": "INGESTED,IN_REVIEW",
}

showURLs = False
dryRun = False
validationErrorMessage, serverSideError, responseBody = TE.Net.updateThreatDescriptor(
    postParams, showURLs, dryRun
)

if validationErrorMessage != None:
    sys.stderr.write(validationErrorMessage + "\n")
    sys.exit(1)

if serverSideError != None:
    sys.stderr.write(str(serverSideError) + "\n")
    sys.stderr.write(json.dumps(responseBody) + "\n")
    sys.exit(1)

print(json.dumps(responseBody))

[(11, 'TE.Net.setAppTokenFromEnvName', 'TE.Net.setAppTokenFromEnvName', False, 'import TE\n'), (20, 'TE.Net.updateThreatDescriptor', 'TE.Net.updateThreatDescriptor', False, 'import TE\n'), (25, 'sys.stderr.write', 'sys.stderr.write', False, 'import sys\n'), (26, 'sys.exit', 'sys.exit', False, 'import sys\n'), (31, 'sys.exit', 'sys.exit', False, 'import sys\n'), (33, 'json.dumps', 'json.dumps', False, 'import json\n'), (30, 'json.dumps', 'json.dumps', False, 'import json\n')]