From dff9a56950210fd0610988c377d5fb349923c566 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Wed, 9 Jun 2021 15:40:35 -0700 Subject: [PATCH] Add len function to notification expressions --- data/interfaces/default/settings.html | 1 + plexpy/helpers.py | 7 +++++++ plexpy/notification_handler.py | 1 + 3 files changed, 9 insertions(+) diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index 618acc6a..b3f056f3 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -1929,6 +1929,7 @@ Rating: {rating}/10 --> Rating: /10
  • divmod(a, b)
  • float(x)
  • int(x)
  • +
  • len(s)
  • round(n[, ndigits])
  • str(x)
  • diff --git a/plexpy/helpers.py b/plexpy/helpers.py index 5faf63c6..ba4e5edb 100644 --- a/plexpy/helpers.py +++ b/plexpy/helpers.py @@ -537,6 +537,13 @@ def helper_divmod(a, b): return 0 +def helper_len(s): + try: + return len(s) + except (ValueError, TypeError): + return 0 + + def helper_round(n, ndigits=None): try: return round(n, ndigits) diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py index dace43b4..05e541ba 100644 --- a/plexpy/notification_handler.py +++ b/plexpy/notification_handler.py @@ -1825,6 +1825,7 @@ def str_eval(field_name, kwargs): 'divmod': helpers.helper_divmod, 'float': helpers.cast_to_float, 'int': helpers.cast_to_int, + 'len': helpers.helper_len, 'round': helpers.helper_round, 'str': str }