From 7f2e5ee5bf59e5814d62990401714e01cd69ba07 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 3 Sep 2023 19:07:30 +0300 Subject: Refactor plugins to own dir --- app/MapPlugin.py | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 app/MapPlugin.py (limited to 'app/MapPlugin.py') diff --git a/app/MapPlugin.py b/app/MapPlugin.py deleted file mode 100644 index abc016b..0000000 --- a/app/MapPlugin.py +++ /dev/null @@ -1,33 +0,0 @@ -from dataclasses import fields -from typing import Any -from app.Item import Item -from app.PluginInterface import Params, PluginInterface -from app.utils import get_param - - -def set_field(item: Item, k: str, v: Any): - field_names = [f.name for f in fields(Item)] - if k not in field_names: - raise Exception(f"Invalid set_field key: {k}") - - setattr(item, k, v) - return item - - -class Plugin(PluginInterface): - def __init__(self, id: str, params: Params) -> None: - super().__init__(id, params) - self.map_expr: str = get_param("map_expr", params) - print(f"[MapItemPlugin#{self.id}] initialized") - - def process(self, source_id: str | None, items: list[Item]) -> list[Item]: - print(f"[MapItemPlugin#{self.id}] process called, n={len(items)}") - if source_id is None: - raise Exception(f"[MapItemPlugin#{self.id}] can not be scheduled") - - expr = f"map(lambda item: {self.map_expr}, input_feed)" - print("expr:") - print(expr) - ret = list(eval(expr, {"input_feed": items, "set_field": set_field})) - print(f"[MapItemPlugin#{self.id}] process returning items, n={len(ret)}") - return ret -- cgit v1.3