2023-11-13 14:45:10 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
1) Website-specific filter (i.e. audiobookbay).
|
|
|
|
|
|
|
|
2) Exclude websites from filtering (e.g. metapedia).
|
|
|
|
|
|
|
|
3) Filter phrases:
|
|
|
|
Refer to sqlitehandler.search_entries for implementation.
|
|
|
|
It is expected to be more complex than function search_entries.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2023-12-11 10:04:45 +01:00
|
|
|
import sqlitehandler as sqlite
|
2023-11-13 14:45:10 +01:00
|
|
|
|
2023-11-26 16:23:52 +01:00
|
|
|
|
2023-11-27 18:22:56 +01:00
|
|
|
async def add_to_list(newwords, keywords):
|
2023-11-13 14:45:10 +01:00
|
|
|
"""
|
2023-11-26 16:23:52 +01:00
|
|
|
Append new keywords to list.
|
2023-11-13 14:45:10 +01:00
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
newwords : str
|
|
|
|
List of new keywords.
|
|
|
|
keywords : str
|
|
|
|
List of current keywords.
|
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
val : str
|
|
|
|
List of current keywords and new keywords.
|
|
|
|
"""
|
2023-12-11 10:04:45 +01:00
|
|
|
if isinstance(keywords, str) or keywords is None:
|
|
|
|
try:
|
|
|
|
keywords = keywords.split(",")
|
|
|
|
except:
|
|
|
|
keywords = []
|
2023-11-13 14:45:10 +01:00
|
|
|
newwords = newwords.lower().split(",")
|
|
|
|
for word in newwords:
|
|
|
|
word = word.strip()
|
|
|
|
if len(word) and word not in keywords:
|
|
|
|
keywords.extend([word])
|
|
|
|
keywords.sort()
|
|
|
|
val = ",".join(keywords)
|
|
|
|
return val
|
|
|
|
|
2023-11-26 16:23:52 +01:00
|
|
|
|
2023-11-27 18:22:56 +01:00
|
|
|
async def remove_from_list(newwords, keywords):
|
|
|
|
"""
|
|
|
|
Remove given keywords from list.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
newwords : str
|
|
|
|
List of new keywords.
|
|
|
|
keywords : str
|
|
|
|
List of current keywords.
|
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
val : str
|
|
|
|
List of new keywords.
|
|
|
|
"""
|
2023-12-11 10:04:45 +01:00
|
|
|
if isinstance(keywords, str) or keywords is None:
|
|
|
|
try:
|
|
|
|
keywords = keywords.split(",")
|
|
|
|
except:
|
|
|
|
keywords = []
|
2023-11-27 18:22:56 +01:00
|
|
|
newwords = newwords.lower().split(",")
|
|
|
|
for word in newwords:
|
|
|
|
word = word.strip()
|
|
|
|
if len(word) and word in keywords:
|
|
|
|
keywords.remove(word)
|
|
|
|
keywords.sort()
|
|
|
|
val = ",".join(keywords)
|
|
|
|
return val
|
|
|
|
|
|
|
|
|
2023-11-26 16:23:52 +01:00
|
|
|
async def is_listed(db_file, key, string):
|
2023-11-23 17:55:36 +01:00
|
|
|
"""
|
|
|
|
Check keyword match.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
db_file : str
|
|
|
|
Path to database file.
|
|
|
|
type : str
|
|
|
|
"allow" or "deny".
|
|
|
|
string : str
|
|
|
|
String.
|
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
Matched keyword or None.
|
|
|
|
|
|
|
|
"""
|
2023-11-13 14:45:10 +01:00
|
|
|
# async def reject(db_file, string):
|
|
|
|
# async def is_blacklisted(db_file, string):
|
2023-12-11 10:04:45 +01:00
|
|
|
list = await sqlite.get_filters_value(
|
2023-11-13 14:45:10 +01:00
|
|
|
db_file,
|
2023-11-26 16:23:52 +01:00
|
|
|
key
|
2023-11-13 14:45:10 +01:00
|
|
|
)
|
|
|
|
if list:
|
|
|
|
list = list.split(",")
|
|
|
|
for i in list:
|
|
|
|
if not i or len(i) < 2:
|
|
|
|
continue
|
|
|
|
if i in string.lower():
|
2023-11-15 15:00:49 +01:00
|
|
|
# print(">>> ACTIVATE", i)
|
2023-11-23 17:55:36 +01:00
|
|
|
# return 1
|
|
|
|
return i
|
2023-11-13 14:45:10 +01:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
This code was tested at module datahandler
|
|
|
|
|
2023-12-11 10:04:45 +01:00
|
|
|
reject = 0
|
|
|
|
blacklist = await get_settings_value(
|
|
|
|
db_file,
|
|
|
|
"filter-deny"
|
|
|
|
)
|
|
|
|
# print(">>> blacklist:")
|
|
|
|
# print(blacklist)
|
|
|
|
# breakpoint()
|
|
|
|
if blacklist:
|
|
|
|
blacklist = blacklist.split(",")
|
|
|
|
# print(">>> blacklist.split")
|
|
|
|
# print(blacklist)
|
|
|
|
# breakpoint()
|
|
|
|
for i in blacklist:
|
|
|
|
# print(">>> length", len(i))
|
|
|
|
# breakpoint()
|
|
|
|
# if len(i):
|
|
|
|
if not i or len(i) < 2:
|
|
|
|
print(">>> continue due to length", len(i))
|
|
|
|
# breakpoint()
|
|
|
|
continue
|
|
|
|
# print(title)
|
|
|
|
# print(">>> blacklisted word:", i)
|
|
|
|
# breakpoint()
|
|
|
|
test = (title + " " + summary + " " + link)
|
|
|
|
if i in test.lower():
|
|
|
|
reject = 1
|
|
|
|
break
|
|
|
|
|
|
|
|
if reject:
|
|
|
|
print("rejected:",title)
|
|
|
|
entry = (title, '', link, source, date, 1);
|
2023-11-13 14:45:10 +01:00
|
|
|
|
|
|
|
"""
|