blob: 85c22295e443dad790bf053a18abd973c5346b4c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
from app.Item import Item
from app.PluginInterface import Params, PluginInterface
from app.utils import get_config
class Plugin(PluginInterface):
def __init__(self, id: str, params: Params) -> None:
super().__init__("FilterPlugin", id, params)
self.filter_expr: str = get_config(params, "filter_expr")
self.log("initialized")
def process(self, source_id: str | None, items: list[Item]) -> list[Item]:
self.log(f"filtering {len(items)} with given filter expression")
if source_id is None:
raise Exception(f"{self.log_prefix} can not be scheduled")
expr = f"filter(lambda item: {self.filter_expr}, input_feed)"
ret = list(eval(expr, {"input_feed": items}))
self.log(f"filtering done, {len(ret)} passed filter")
return ret
|