-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblacklist_func.py
45 lines (38 loc) · 1.1 KB
/
blacklist_func.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os, paths
def delete(filename, verbose=True):
if(not os.path.exists(filename)):
if (verbose):
print("Файл "+filename+" не существует!")
return
try:
print("rm "+filename)
os.remove(filename)
except:
if(verbose):
print("Ошибка удаления, проверьте права")
def getBlackList(filename=paths.blacklistfile):
if not os.path.exists(filename):
open(filename, "a").close()
arr=open(filename).read().splitlines()
arr=[x for x in arr if x != ""]
return arr
def blacklistCleanup(echoes):
global blacklist
for echo in echoes:
if(os.path.exists(paths.indexdir+echo)):
msglist=open(paths.indexdir+echo).read().splitlines()
else:
continue
msglist=[x for x in msglist if x not in blacklist]
print("saving echo "+echo)
f=open(os.path.join(paths.indexdir, echo), "w")
f.write("\n".join(msglist)+"\n")
f.close()
print("cleaning messages")
for msgid in blacklist:
delete(os.path.join(paths.msgdir, msgid))
def applyBlacklist(echo):
global blacklist
echo=[x for x in echo if x not in blacklist]
return echo
blacklist=getBlackList()