41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
|
|
|
|
def filter(article, file):
|
|
filterList = ()
|
|
result = 'some'
|
|
|
|
|
|
try:
|
|
with open(file, "r") as f:
|
|
filterList = f.read().split('\n')
|
|
except:
|
|
with open(file, 'w') as f:
|
|
f.write('# +Word to include / -Word to exclude / !Word to highlight and include / *Word to pin and include; one word per list; Format: +Category=Word')
|
|
return result
|
|
|
|
if len(filterList) > 0:
|
|
for item in filterList:
|
|
try:
|
|
if item[0] == '#': continue
|
|
cat = item[1:].split('=')[0]
|
|
word = item[1:].split('=')[1]
|
|
except:
|
|
continue
|
|
try:
|
|
if article[cat].find(word) != -1:
|
|
if item[0] == '+':
|
|
result = 'all'
|
|
if item[0] == '-':
|
|
result = 'none'
|
|
if item[0] == '!':
|
|
result = 'important'
|
|
if item[0] == '*':
|
|
result = 'pinned'
|
|
except:
|
|
continue
|
|
|
|
if file == 'none' and result == 'all':
|
|
result = 'some'
|
|
|
|
return result |