tv urlwatch exec: use dict-based filter list

Because string-based filter definitions are deprecated since 2.19

Refs https://urlwatch.readthedocs.io/en/latest/deprecated.html
This commit is contained in:
tv 2023-02-02 15:24:04 +01:00
parent 38062bf066
commit beab66db65

View File

@ -2,9 +2,10 @@ with import ./lib;
{ config, pkgs, ... }: let { config, pkgs, ... }: let
exec = filename: args: url: { exec = filename: args: url: {
inherit url; inherit url;
filter = "system:${ filter = singleton {
concatMapStringsSep " " shell.escape ([filename] ++ toList args) system =
}"; concatMapStringsSep " " shell.escape ([filename] ++ toList args);
};
}; };
json = json' ["."]; json = json' ["."];
json' = exec "${pkgs.jq}/bin/jq"; json' = exec "${pkgs.jq}/bin/jq";
@ -73,17 +74,23 @@ in {
import subprocess import subprocess
import urlwatch import urlwatch
class CaseFilter(urlwatch.filters.FilterBase): class SystemFilter(urlwatch.filters.FilterBase):
"""Filter for piping data through an external process""" """Filter for piping data through an external process"""
__kind__ = 'system' __kind__ = 'system'
__supported_subfilters__ = {
'command': 'shell command line to tranform data',
}
__default_subfilter__ = 'command'
def filter(self, data, subfilter=None): def filter(self, data, subfilter=None):
if subfilter is None: if 'command' not in subfilter:
raise ValueError('The system filter needs a command') raise ValueError('{} filter needs a command'.format(self.__kind__))
proc = subprocess.Popen( proc = subprocess.Popen(
subfilter, subfilter['command'],
shell=True, shell=True,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,