mirror of https://gitlab.com/bashrc2/epicyon
Tidying
parent
19069c7b1d
commit
34d2576ed2
26
filters.py
26
filters.py
|
@ -47,16 +47,19 @@ def removeFilter(baseDir: str, nickname: str, domain: str,
|
||||||
"""
|
"""
|
||||||
filtersFilename = baseDir + '/accounts/' + \
|
filtersFilename = baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/filters.txt'
|
nickname + '@' + domain + '/filters.txt'
|
||||||
if os.path.isfile(filtersFilename):
|
if not os.path.isfile(filtersFilename):
|
||||||
if words in open(filtersFilename).read():
|
return False
|
||||||
|
if words not in open(filtersFilename).read():
|
||||||
|
return False
|
||||||
|
newFiltersFilename = filtersFilename + '.new'
|
||||||
with open(filtersFilename, 'r') as fp:
|
with open(filtersFilename, 'r') as fp:
|
||||||
with open(filtersFilename + '.new', 'w+') as fpnew:
|
with open(newFiltersFilename, 'w+') as fpnew:
|
||||||
for line in fp:
|
for line in fp:
|
||||||
line = line.replace('\n', '')
|
line = line.replace('\n', '')
|
||||||
if line != words:
|
if line != words:
|
||||||
fpnew.write(line + '\n')
|
fpnew.write(line + '\n')
|
||||||
if os.path.isfile(filtersFilename + '.new'):
|
if os.path.isfile(newFiltersFilename):
|
||||||
os.rename(filtersFilename + '.new', filtersFilename)
|
os.rename(newFiltersFilename, filtersFilename)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -65,16 +68,19 @@ def removeGlobalFilter(baseDir: str, words: str) -> bool:
|
||||||
"""Removes a global word filter
|
"""Removes a global word filter
|
||||||
"""
|
"""
|
||||||
filtersFilename = baseDir + '/accounts/filters.txt'
|
filtersFilename = baseDir + '/accounts/filters.txt'
|
||||||
if os.path.isfile(filtersFilename):
|
if not os.path.isfile(filtersFilename):
|
||||||
if words in open(filtersFilename).read():
|
return False
|
||||||
|
if words not in open(filtersFilename).read():
|
||||||
|
return False
|
||||||
|
newFiltersFilename = filtersFilename + '.new'
|
||||||
with open(filtersFilename, 'r') as fp:
|
with open(filtersFilename, 'r') as fp:
|
||||||
with open(filtersFilename + '.new', 'w+') as fpnew:
|
with open(newFiltersFilename, 'w+') as fpnew:
|
||||||
for line in fp:
|
for line in fp:
|
||||||
line = line.replace('\n', '')
|
line = line.replace('\n', '')
|
||||||
if line != words:
|
if line != words:
|
||||||
fpnew.write(line + '\n')
|
fpnew.write(line + '\n')
|
||||||
if os.path.isfile(filtersFilename + '.new'):
|
if os.path.isfile(newFiltersFilename):
|
||||||
os.rename(filtersFilename + '.new', filtersFilename)
|
os.rename(newFiltersFilename, filtersFilename)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue