InRange

checks if left side is in range of right side (from,to anotation) e.g. - InRange left=4right=1,8 will return true.

python · Filters And Transformers

Source

import demistomock as demisto  # noqa: F401
from CommonServerPython import *  # noqa: F401

INVALID_ARG = "INVALID_ARG"


def to_float(s):
    try:
        return float(s)
    except Exception:
        return INVALID_ARG


# "1,8" => will return a tupple (1, 8)


def parse_range(rangeStr):
    splitted = rangeStr.split(",")
    if len(splitted) < 2:
        return INVALID_ARG, INVALID_ARG

    # parse
    return to_float(splitted[0]), to_float(splitted[1])


def main():
    leftArg = demisto.args()["left"]
    rightArg = demisto.args()["right"]

    left = to_float(leftArg)
    fromRange, toRange = parse_range(rightArg)

    if INVALID_ARG in [left, fromRange, toRange]:
        demisto.error(
            "InRange - invalid arguments. left shuld be a number, right should be from,to (e.g. '1,8'). "
            f"got left - {leftArg}, right - {rightArg}"
        )
        demisto.results(False)
    else:
        demisto.results(left >= fromRange and left <= toRange)


if __name__ in ("__main__", "__builtin__", "builtins"):
    main()

README

Checks if the left side is in range of the right side (from,to anotation).

Example - InRange left=4right=1,8 will return true

Script Data


Name Description
Script Type python3
Tags filter, number

Inputs


Argument Name Description
left The value to check, if it is in range. For example, 4.
right The range to check against with the form of from,to. For example, 2,8.

Outputs


There are no outputs for this script.