aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/__init__.py0
-rw-r--r--core/entry_filter.py31
2 files changed, 31 insertions, 0 deletions
diff --git a/core/__init__.py b/core/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/core/__init__.py
diff --git a/core/entry_filter.py b/core/entry_filter.py
new file mode 100644
index 0000000..62ab9f5
--- /dev/null
+++ b/core/entry_filter.py
@@ -0,0 +1,31 @@
+import fnmatch
+
+def filter_entry(config, agent, entry):
+ start_with_list = [name[1]['title'] for name in config['agents'].items()]
+ style_block = [name[1]['style_block'] for name in config['agents'].items()]
+ [start_with_list.append('<pre') for i in style_block if i]
+
+ # Todo Compatible with whitelist/blacklist parameter, to be removed
+ allow_list = agent[1].get('allow_list') if agent[1].get('allow_list') is not None else agent[1].get('whitelist')
+ deny_list = agent[1]['deny_list'] if agent[1].get('deny_list') is not None else agent[1].get('blacklist')
+
+ # filter, if not content starts with start flag
+ if not entry['content'].startswith(tuple(start_with_list)):
+
+ # filter, if in allow_list
+ if allow_list is not None:
+ if any(fnmatch.fnmatch(entry['feed']['site_url'], pattern) for pattern in allow_list):
+ return True
+
+ # filter, if not in deny_list
+ elif deny_list is not None:
+ if any(fnmatch.fnmatch(entry['feed']['site_url'], pattern) for pattern in deny_list):
+ return False
+ else:
+ return True
+
+ # filter, if allow_list and deny_list are both None
+ elif allow_list is None and deny_list is None:
+ return True
+
+ return False