diff --git a/common/logger.py b/common/logger.py new file mode 100644 index 0000000..cd05a28 --- /dev/null +++ b/common/logger.py @@ -0,0 +1,10 @@ +import logging +from yaml import safe_load + +config = safe_load(open('config.yml', encoding='utf8')) +logger = logging.getLogger(__name__) +logger.setLevel(config.get('log_level', 'INFO')) +formatter = logging.Formatter('%(asctime)s - %(filename)s - %(lineno)d - %(levelname)s - %(message)s') +console = logging.StreamHandler() +console.setFormatter(formatter) +logger.addHandler(console) diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 0000000..e69de29 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('\n' diff --git a/tests/test_filter.py b/tests/test_filter.py new file mode 100644 index 0000000..5aa4add --- /dev/null +++ b/tests/test_filter.py @@ -0,0 +1,125 @@ +import unittest +from yaml import safe_load +from core.entry_filter import filter_entry + +test_config = ''' +{ + "test_style_block": { + "agents": { + "test": { + "title": "🌐AI 翻译", + "style_block": true, + "allow_list": , + "deny_list": + } + } + }, + "test_allow_list": { + "agents": { + "test": { + "title": "🌐AI 翻译", + "style_block": false, + "allow_list": [ + "https://9to5mac.com/", + "https://home.kpmg/*" + ], + "deny_list": + } + } + }, + "test_deny_list": { + "agents": { + "test": { + "title": "🌐AI 翻译", + "style_block": false, + "allow_list": , + "deny_list": [ + "https://9to5mac.com/", + "https://home.kpmg/cn/zh/home/insights.html" + ] + } + } + }, + "test_None": { + "agents": { + "test": { + "title": "🌐AI 翻译", + "style_block": false, + "allow_list": , + "deny_list": + } + } + } +} +''' + +test_entries = ''' +{ + "test_style_block": + { + "entry": + { + "content": '