-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathii-search.py
executable file
·108 lines (91 loc) · 2.8 KB
/
ii-search.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
import os, sys, datetime
from ii_functions import *
dformat="%Y%m%d" # format for date input
def getReadableMsg(msg):
msgid=msg.get('id')
subj=msg.get('subj')
sender=msg.get('sender')
addr=msg.get('addr')
to=msg.get('to')
echo=msg.get('echo')
if msg['repto']:
repto=msg.get("repto")
else:
repto="-"
msgtext="msgid: "+msgid+"\n"+echo+"\nОтвет на: "+repto+"\n"+formatDate(msg.get('time'))+"\n"+subj+"\n"+sender+" ("+addr+") -> "+to+"\n\n"+msg.get("msg")
return msgtext
def sortByTime(msg):
return float(msg.get("time"))
check_dirs()
echo=input("Введите нужную эху(эхи): ").split(" ")
senders=input("Введите поинтов-отправителей (разделитель ||): ").split("||")
receivers=input("Введите поинтов-получателей (разделитель ||): ").split("||")
address=input("Адрес станции поинта (разделитель ||): ").split("||")
timeprom=input("Введите промежуток времени в формате '20140805 20140920': ").split(" ")
subj=input("Введите тему сообщения: ")
text=input("Введите строку для поиска: ")
dateone=datetime.datetime(1970,1,1)
datetwo=datetime.datetime.today()
if len(timeprom)==2:
dateone=datetime.datetime.strptime(timeprom[0], dformat)
datetwo=datetime.datetime.strptime(timeprom[1], dformat)
index=[]
if not echo[0]:
for echoarea in os.listdir(indexdir):
index+=getMsgList(echoarea)
else:
for x in echo:
index+=getMsgList(x)
if len(index)<=0:
print("База пуста (проверьте права доступа).")
exit()
print("Загрузка базы...")
msglist={}
removelist=[]
for x in index:
msglist[x]=getMsg(x)
print("Фильтрация сообщений...\n")
for msg in msglist.values():
c=False
for point in senders:
if str(point) in msg["sender"]:
c=True
break
d=False
for addr in address:
if str(addr) in msg["addr"]:
d=True
break
e=False
for point in receivers:
if str(point) in msg["to"]:
e=True
break
msgdate=datetime.datetime.fromtimestamp(float(msg.get("time")))
if (
(c and d and e) is False or
(subj not in msg["subj"]) or
(text not in msg["msg"]) or
(msgdate<dateone) or
(msgdate>datetwo)
):
if msg.get("id"):
removelist.append(msg["id"])
for i in removelist:
msglist.__delitem__(i)
if len(msglist)==0:
print("Сообщения не найдены.")
else:
print("Найдено сообщений: "+str(len(msglist)))
for msg in sorted(msglist.values(), key=sortByTime):
print("====----====")
print(getReadableMsg(msg))
args=sys.argv[1:]
if len(args)==1:
try:
f=open(args[0], "w")
f.write("\n".join(msglist)+"\n")
f.close()
except Exception as e:
print("Ошибка записи в файл: "+str(e))