-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
674 lines (571 loc) · 28.5 KB
/
logger.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
import os, codecs, requests
import subprocess, threading
from pystray import MenuItem, Menu, Icon
from time import sleep
from datetime import datetime, timedelta
import psutil, json
from pymongo import MongoClient
from tkinter import WORD, ttk, HORIZONTAL, VERTICAL, Label, scrolledtext, END
from ttkthemes import ThemedTk
from PIL import Image
from bson.json_util import dumps
from constants import *
class LogViewer(ThemedTk):
def __init__(self):
# Setting up Player window.
super().__init__(theme="equilux")
self.geometry("743x440")
self['background'] = "#464646"
self.title("LogViewer")
self.resizable(False, False)
self.iconbitmap('icon.ico')
self.setup_ui()
def setup_ui(self):
self.from_label = Label(self, text="Logger's logs")
self.from_label['background'] = "#464646"
self.from_label['foreground'] = "#BEBEBE"
self.to_label = Label(self, text="Checker's logs")
self.to_label['background'] = "#464646"
self.to_label['foreground'] = "#BEBEBE"
self.stoplog = Label(self, text="Логгер приостановлен", font=("roobert", 15))
self.stoplog['background'] = "#464646"
self.stoplog['foreground'] = "#BEBEBE"
self.stopcheck = Label(self, text="Чеккер приостановлен", font=("roobert", 15))
self.stopcheck['background'] = "#464646"
self.stopcheck['foreground'] = "#BEBEBE"
self.hseparatorTOP = ttk.Separator(self, orient=HORIZONTAL)
self.hseparatorMID = ttk.Separator(self, orient=HORIZONTAL)
self.hseparatorBOT = ttk.Separator(self, orient=HORIZONTAL)
self.vseparatorLEFT = ttk.Separator(self, orient=VERTICAL)
self.vseparatorMID = ttk.Separator(self, orient=VERTICAL)
self.vseparatorRIGHT = ttk.Separator(self, orient=VERTICAL)
self.logger_console = scrolledtext.ScrolledText(self, wrap=WORD, width=50, height=50, font=("roobert", 9))
self.logger_console['background'] = "#18181b"
self.checker_console = scrolledtext.ScrolledText(self, wrap=WORD, width=50, height=50, font=("roobert", 9))
self.checker_console['background'] = "#18181b"
self.hseparatorMID.place(x=2, y=220, relwidth=0.995, relheight=0.01)
self.hseparatorBOT.place(x=2, y=437, relwidth=.995, relheight=0.03)
self.vseparatorLEFT.place(x=0, y=2, relwidth=0.003, relheight=0.994)
self.vseparatorMID.place(x=740, y=2, relwidth=0.003, relheight=0.994)
self.vseparatorRIGHT.place(x=857, y=2, relwidth=0.003, relheight=0.994)
self.hseparatorTOP.place(x=2, y=0, relwidth=0.995, relheight=0.01)
self.from_label.place(x=10, y=5)
self.to_label.place(x=10, y=228)
self.logger_console.place(x=11, y=30, height=180, width=715)
self.checker_console.place(x=11, y=253, height=175, width=715)
self.logger_console.tag_config("timestamp", foreground="#4dd64f")
self.logger_console.tag_config("draw", foreground="#269e28")
self.logger_console.tag_config("log", foreground="#c8c8c8")
self.logger_console.tag_config("info", foreground="#0027a6")
self.logger_console.tag_config("starting", foreground="#0ae002")
self.logger_console.tag_config("fatal", foreground="#c20000")
self.logger_console.tag_config("exception", foreground="#d6d60d")
self.checker_console.tag_config("timestamp", foreground="#4dd64f")
self.checker_console.tag_config("draw", foreground="#269e28")
self.checker_console.tag_config("log", foreground="#c8c8c8")
self.checker_console.tag_config("info", foreground="#0027a6")
self.checker_console.tag_config("starting", foreground="#0ae002")
self.checker_console.tag_config("request", foreground="#33cccc")
self.checker_console.tag_config("answer", foreground="#3399cc")
self.checker_console.tag_config("exception", foreground="#d6d60d")
def adding_log_to_console(self, mess):
self.logger_console.configure(state='normal')
spltd = mess.split()
log = mess.split(spltd[0])[1]
if spltd[0] == "Info:":
self.logger_console.insert(END, " " + spltd[0], "info")
self.logger_console.insert(END, " " + log + "\n", "log")
elif spltd[0] == "Fatal:":
self.logger_console.insert(END, " " + spltd[0], "fatal")
self.logger_console.insert(END, " " + log + "\n", "log")
elif spltd[0] == "Starting:":
self.logger_console.insert(END, " " + spltd[0], "starting")
self.logger_console.insert(END, " " + log + "\n", "log")
elif spltd[0] in ["Exception:", "Decoding:", "Connection:"]:
self.logger_console.insert(END, " " + spltd[0], "exception")
self.logger_console.insert(END, " " + log + "\n", "log")
else:
self.logger_console.insert(END, " " + "[" + " ", "draw")
self.logger_console.insert(END, spltd[0][:-1], "timestamp")
self.logger_console.insert(END, " " + "]" + " ", "draw")
self.logger_console.insert(END, log + "\n", "log")
self.logger_console.yview(END)
self.logger_console.configure(state='disabled')
def adding_check_to_console(self, mess):
self.checker_console.configure(state='normal')
messtype = mess.split("$TYPE$")[1]
messbody = mess.split("$MESS$")[1]
if messtype == "Info":
self.checker_console.insert(END, " " + messtype + ":", "info")
self.checker_console.insert(END, " " + messbody + "\n", "log")
elif messtype == "Starting":
self.checker_console.insert(END, " " + messtype + ":", "starting")
self.checker_console.insert(END, " " + messbody + "\n", "log")
elif messtype == "Exception":
self.checker_console.insert(END, " " + messtype + ":", "exception")
self.checker_console.insert(END, " " + messbody + "\n", "log")
if "$TIME$" in mess:
messtime = mess.split("$TIME$")[1]
if messtype == "[Answer]":
self.checker_console.insert(END, " " + messtype, "answer")
self.checker_console.insert(END, " " + "[" + " ", "draw")
self.checker_console.insert(END, messtime, "timestamp")
self.checker_console.insert(END, " " + "]" + " ", "draw")
self.checker_console.insert(END, " : " + messbody + "\n", "log")
elif messtype == "[Request]":
self.checker_console.insert(END, " " + messtype, "request")
self.checker_console.insert(END, " " + "[" + " ", "draw")
self.checker_console.insert(END, messtime, "timestamp")
self.checker_console.insert(END, " " + "]" + " ", "draw")
self.checker_console.insert(END, " : " + messbody + "\n", "log")
self.checker_console.yview(END)
self.checker_console.configure(state='disabled')
def print_logger(self, mess):
global logger_logs
if mess != "update":
if on_console != "logger" and not iconified:
if logger_logs:
for past_mess in logger_logs:
self.adding_log_to_console(past_mess)
logger_logs = []
else:
self.adding_log_to_console(mess)
else:
logger_logs.append(mess)
else:
if logger_logs:
for past_mess in logger_logs:
self.adding_log_to_console(past_mess)
logger_logs = []
def print_checker(self, mess):
global checker_logs
if mess != "update":
if on_console != "checker":
if checker_logs:
for past_mess in checker_logs:
self.adding_check_to_console(past_mess)
checker_logs = []
else:
self.adding_check_to_console(mess)
else:
checker_logs.append(mess)
else:
if checker_logs:
for past_mess in checker_logs:
self.adding_check_to_console(past_mess)
checker_logs = []
class LogRequest:
def __init__(self, syncid):
self.syncID = syncid
self.streamer = ""
self.date_from = ""
self.date_to = ""
self.body = ""
self.user = ""
self.mentions = []
self.moderationMSG = False
self.andMode = True
def __str__(self):
return f"{self.streamer} {self.date_from} {self.date_to} {self.user} {self.body} {self.mentions}"
def set_body(self, body):
self.body = body
def set_streamer(self, _streamer):
self.streamer = _streamer
def set_date(self, date_from, date_to):
self.date_from, self.date_to = date_from, date_to
def set_user(self, user):
self.user = user
def set_mentions(self, mention_list):
if mention_list == "":
mention_list = []
self.mentions = mention_list
def moderation(self, boolean):
self.moderationMSG = boolean
# noinspection PyUnusedLocal,PyShadowingNames
def quit_window(icon, MenuItem):
global loop, checker_thread, logger_thread, chatterino_thread, GUI
icon.stop()
loop = False
GUI.destroy()
# noinspection PyUnusedLocal,PyShadowingNames
def show_window(icon, MenuItem):
icon.stop()
GUI.after(0, GUI.deiconify)
def withdraw_window():
GUI.withdraw()
image = Image.open("icon.ico")
menu = Menu(MenuItem('Выход', quit_window), MenuItem('Открыть', show_window))
icon = Icon("LogViwer", image, "LogViwer", menu)
icon.run()
def is_mouse_on_console():
global on_console, GUI
abs_coord_x = GUI.winfo_pointerx() - GUI.winfo_rootx()
abs_coord_y = GUI.winfo_pointery() - GUI.winfo_rooty()
if 10 < abs_coord_x < 725 and 30 < abs_coord_y < 207:
on_console = "logger"
elif 10 < abs_coord_x < 725 and 255 < abs_coord_y < 425:
on_console = "checker"
else:
on_console = False
def checker():
global last_logChecker
while True:
sleep(1)
try:
logreqs = []
response = requests.get("https://cyberinquisitor414.glitch.me/LOGWIEWIERdb", proxies=proxy).json()
except json.decoder.JSONDecodeError:
last_logChecker = f"$TYPE$Exception$TYPE$$MESS$Не удалось прочесть: " \
f" https://cyberinquisitor414.glitch.me/LOGWIEWIERdb$MESS$"
continue
if response["whatweneed"]:
for req in response["whatweneed"]:
formated_req = f"\n\n Стример: {req['streamer']} \n От: {req['dateFrom']} \n" \
f" До: {req['dateTo']} \n Ник: {req['user']} \n SyncID: {req['SyncID']} \n"
time_now = datetime.now().replace(microsecond=0).isoformat()
last_logChecker = f"$TYPE$[Request]$TYPE$$TIME${time_now}$TIME$$MESS${formated_req}$MESS$"
sleep(1)
rawlogreq = LogRequest(str(req["SyncID"]))
rawlogreq.set_streamer(req["streamer"])
rawlogreq.set_user(req["user"].lower())
rawlogreq.set_date(req["dateFrom"], req["dateTo"])
if "moderationMsg" in req:
rawlogreq.moderation(True)
if "mention" in req:
rawlogreq.set_mentions(req["mention"])
if "msgBody" in req:
rawlogreq.set_body(req["msgBody"])
logreqs.append(rawlogreq)
for logreq in logreqs:
post_data = {"SyncID": logreq.syncID, "Exceptions": [], "data": {}}
if logreq.streamer in db.list_collection_names():
list_of_mess = list(db[logreq.streamer].find({"user": logreq.user}))
if list_of_mess:
timeline_mess_list = []
dateFrom = datetime.strptime(f'{logreq.date_from}', "%Y-%m-%dT%H:%M:%S.%fZ").replace(
microsecond=0)
dateTo = datetime.strptime(f'{logreq.date_to}', "%Y-%m-%dT%H:%M:%S.%fZ").replace(
microsecond=0)
for mess in list_of_mess:
mess.pop('_id')
messDate = mess["date"]
mess["date"] = str(mess["date"].isoformat()) + "Z"
if dateFrom <= messDate <= dateTo:
timeline_mess_list.append(mess)
if timeline_mess_list:
mentionValid_mess_list = []
if logreq.mentions:
for mess1 in timeline_mess_list:
if logreq.mentions == mess1["mentions"]:
mentionValid_mess_list.append(mess1)
if not mentionValid_mess_list and logreq.andMode:
post_data["Exceptions"].append("No matching mentions in messages.")
else:
mentionValid_mess_list = timeline_mess_list
wordValid_mess_list = []
if logreq.andMode and mentionValid_mess_list:
if logreq.body != "":
for mess2 in mentionValid_mess_list:
if logreq.body in mess2["body"]:
wordValid_mess_list.append(mess2)
else:
wordValid_mess_list = mentionValid_mess_list
if wordValid_mess_list:
post_data["data"] = wordValid_mess_list
else:
post_data["Exceptions"].append(
"There are no matching words in the messages")
elif not logreq.andMode and mentionValid_mess_list:
if logreq.body != "":
for mess2 in mentionValid_mess_list:
if logreq.body in mess2["body"]:
wordValid_mess_list.append(mess2)
else:
wordValid_mess_list = mentionValid_mess_list
if not wordValid_mess_list and mentionValid_mess_list:
post_data["data"] = mentionValid_mess_list
post_data["Exceptions"].append(
"There are no matching words in the messages, but there are matching mentions")
elif wordValid_mess_list and not mentionValid_mess_list:
post_data["data"] = wordValid_mess_list
post_data["Exceptions"].append(
"There are no matching mentions in the messages, but there are matching words")
elif not wordValid_mess_list and not mentionValid_mess_list:
post_data["Exceptions"].append(
"There are no matching words or mentions in the messages")
else:
post_data["Exceptions"].append("Not matching messages in this timeline.")
else:
post_data["Exceptions"].append("No matching messages.")
else:
post_data["Exceptions"].append("Streamer not in DB.")
requests.post("https://cyberinquisitor414.glitch.me/logsresponce",
json=json.loads(dumps(post_data)),
headers=headersCT, proxies=proxy)
time_now = datetime.now().replace(microsecond=0).isoformat()
last_logChecker = f"$TYPE$[Answer]$TYPE$$TIME${time_now}$TIME$" \
f"$MESS$Отправлено сообшений {len(post_data['data'])}$MESS$"
sleep(1)
def logger():
global last_logLogger
# Чекируем стримеров, стримы и сообщения.
sleep(5)
while True:
for streamer in streamerlist:
try:
sleep(2)
stream_state, log_state, streamer_state = "", "", ""
# Streams
stream_info = checkdb_streams(streamer)
if type(stream_info) != int:
stream_state = stream_info
# Streamers
streamer_info = getstreamerinfo(streamer)
if len(streamer_info) == 2:
last_logLogger = f"{streamer_info[0]}\n"
continue
streamer_id = streamer_info[0]
streamer_status = streamer_info[1]
streamer_db_action = checkdb_streamer(streamer, streamer_id, streamer_status)
if type(streamer_db_action) != int:
streamer_state = streamer_db_action
# Logs
streamer_logs = path_to_logs + streamer + "\\"
logs_status = checkdb_messages(streamer_logs, streamer)
log_state = logs_status[0]
if logs_status[1] == 0:
continue
time_now = datetime.now().replace(microsecond=0).isoformat()
last_logLogger = f"{time_now}: {log_state} {streamer_state} {stream_state}"
except UnicodeDecodeError or ValueError:
last_logLogger = f"Decoding: Возникла ошибка при декодировании, когда читали логи {streamer}"
def logs_to_console():
global last_logLoggerOLD, last_logLogger, last_logCheckerOLD, last_logChecker
if last_logLoggerOLD != last_logLogger:
GUI.print_logger(last_logLogger)
last_logLoggerOLD = last_logLogger
if last_logCheckerOLD != last_logChecker:
GUI.print_checker(last_logChecker)
last_logCheckerOLD = last_logChecker
is_mouse_on_console()
if on_console == "logger":
GUI.stoplog.place(x=250, y=0)
else:
GUI.print_logger("update")
GUI.stoplog.place_forget()
if on_console == "checker":
GUI.stopcheck.place(x=250, y=223)
else:
GUI.print_checker("update")
GUI.stopcheck.place_forget()
GUI.after(100, func=logs_to_console)
def check_of_chatterino():
for process_ifc in psutil.process_iter():
if "chatterino.exe" == process_ifc.name():
return "Info: Chatterino обнаружен.", 1
return "Info: Chatterino не обнаружен.", 0
def chatterino_subprocess():
process = subprocess.Popen([f"{path_to_chatterino}chatterino.exe"], stdout=subprocess.DEVNULL)
while True:
if not loop:
process.terminate()
return
sleep(1)
def checkdb_streams(channel_name):
stream_status = getstreamerinfo(channel_name, "streams")
if type(stream_status) == str:
return stream_status
if not db["streams"].find_one({"name": stream_status[0]}):
db["streams"].insert_one({
"streamer": channel_name,
"name": stream_status[0],
"id": stream_status[1],
"created_at": stream_status[2],
"finished_at": ""})
return f'Стрим "{stream_status[0]}" от "{channel_name}" добавлен в базу данных.'
return 1
def going_offline(channel_name):
timenow_utc = datetime.now().replace(microsecond=0).isoformat()
db["streams"].update_one({"streamer": channel_name},
{"$set": {"finished_at": timenow_utc}})
def getstreamerinfo(channel_name, datatype="id+status"):
id_req = requests.get(f'https://api.twitch.tv/kraken/users?login={channel_name}',
headers=headersAC, proxies=proxy).json()
if 'error' in id_req:
return f"{channel_name} не найден, пропускаю.", 0
if id_req['_total'] == 0:
return f"{channel_name} не найден, пропускаю.", 0
channel_id = id_req['users'][0]['_id']
if datatype == "id+status":
status_req = requests.get(f"https://api.twitch.tv/kraken/channels/{channel_id}",
headers=headersAC, proxies=proxy).json()
return channel_id, status_req["status"], 1
elif datatype == "streams":
stream_req = requests.get(f"https://api.twitch.tv/kraken/streams/?channel={channel_id}",
headers=headersAC, proxies=proxy).json()
if not stream_req["streams"]:
going_offline(channel_name)
return f"{channel_name} в офлайне."
stream_now = stream_req["streams"][0]
return stream_now["channel"]["status"], stream_now["_id"], stream_now["created_at"]
def addtodb_streamer(channel_name, _id, status):
streamer_logs_ = path_to_logs + channel_name + "\\"
if not os.path.exists(streamer_logs_):
return f"Exception: Не найдена папка с логами {channel_name}"
list_of_logs = [os.path.join(streamer_logs_, i) for i in os.listdir(streamer_logs_)]
for logfile in sorted(list_of_logs, key=os.path.getmtime):
streamerlist[channel_name]["logfiles"][logfile] = 0
db.create_collection(channel_name)
db["streamers"].insert_one({
"name": channel_name,
"id": _id,
"status": status,
"logfiles": streamerlist[channel_name]["logfiles"]})
def checkdb_streamer(channel_name, _id, status):
streamer_inf = db["streamers"].find_one({"name": channel_name})
last_logfiles = streamerlist[channel_name]["logfiles"]
if streamer_inf is None:
adding_status_ = addtodb_streamer(channel_name, _id, status)
if type(adding_status_) is str:
return adding_status_
return f"{channel_name} не в базе данных, добавляем."
if streamer_inf["status"] != status:
db["streamers"].update_one({"name": channel_name}, {"$set": {"status": status}})
return f"Обновляем статус у {channel_name} в базе данных."
if streamer_inf["logfiles"] != last_logfiles:
db["streamers"].update_one({"name": channel_name}, {"$set": {"logfiles": last_logfiles}})
return 1
def addtodb_message(log_line, _streamer, log_date):
if log_line[0] != "#" and len(log_line.split()) > 2:
if ":" not in log_line[12:]:
is_moderation = True
user = log_line.split()[1]
body = log_line.split(user)[1]
else:
is_moderation = False
user = log_line[12:].split(":")[0]
body = log_line[12:].split(":")[1][1:]
else:
return "Exception"
logline_time = log_line.split("]")[0][1:]
date = (datetime.fromisoformat(f"{log_date}T{logline_time}") - timedelta_from_UTC).replace(microsecond=0)
stream_id = "offline"
last_stream = db["streams"].find_one({"streamer": _streamer})
if last_stream:
if last_stream["finished_at"] == "":
stream_id = last_stream["id"]
mentions = [word for word in body.split() if "@" in word]
if body.endswith('\n'):
body = body[:-1]
db[_streamer].insert_one({
"date": date,
"user": user,
"mentions": mentions,
"body": body,
"stream_id": stream_id,
"moderationMSG": is_moderation})
def getinfo_lastlog(_streamer_logs, _streamer):
rows_added = 0
rows_skipped = 0
logging = []
for logfile in streamerlist[_streamer]["logfiles"].keys():
logline = streamerlist[_streamer]["logfiles"][logfile]
log_file = codecs.open(logfile, "r", "utf-8-sig", errors='ignore')
loglines = log_file.readlines()
if len(loglines) > logline:
log_date = logfile.split(_streamer)[-1][1:11]
for log_line in loglines[logline:]:
try:
if addtodb_message(log_line, _streamer, log_date) != "Exception":
rows_added += 1
except ValueError:
rows_skipped += 1
streamerlist[_streamer]["logfiles"][logfile] = len(loglines)
list_of_logs = [os.path.join(_streamer_logs, i) for i in os.listdir(_streamer_logs)]
lastests = sorted(list_of_logs, key=os.path.getmtime)
log_files_inDB = streamerlist[_streamer]["logfiles"].keys()
if rows_skipped != 0:
logging.append(f"пропущено строк {rows_skipped}")
if lastests != log_files_inDB:
for new_logfile in lastests:
if new_logfile not in log_files_inDB:
streamerlist[_streamer]["logfiles"][new_logfile] = 0
logging.append("найден новый лог-файл")
if rows_added != 0:
if logging:
return f"добавлено {rows_added} cтрок в базу данных, {', '.join(logging)}."
return f"добавлено {rows_added} cтрок в базу данных."
if logging:
return f"пока нечего читать, {', '.join(logging)}."
return f"пока нечего читать."
def checkdb_messages(_streamer_logs, _streamer):
if not os.path.exists(_streamer_logs) or os.listdir(_streamer_logs) == []:
return f"Не найдены логи стримера {_streamer}, пропускаю.", 0
addtodb_inf = getinfo_lastlog(_streamer_logs, _streamer)
if addtodb_inf:
return f"Читаем логи {_streamer}, {addtodb_inf}", 1
else:
return f"Читаем логи {_streamer}.", 1
loop = True
logger_thread = threading.Thread(target=logger)
chatterino_thread = threading.Thread(target=chatterino_subprocess)
checker_thread = threading.Thread(target=checker)
logger_thread.daemon = True
chatterino_thread.daemon = True
checker_thread.daemon = True
mongodb = MongoClient(connect_string)
db = mongodb["main"]
result_check_of_chatterino = check_of_chatterino()
if check_of_chatterino()[1] == 1:
preStartInfo.append(result_check_of_chatterino[0])
else:
if os.path.exists(path_to_chatterino):
preStartInfo.append("Info: Chatterino не обнаружен, запускаем.")
chatterino_thread.start()
else:
preStartExceptions.append("Exception: Неправильный путь к папке Chatterino.")
if not os.path.exists(path_to_logs):
preStartExceptions.append("Exception: Не найдена папка логов.")
GUI = LogViewer()
on_console = False
iconified = False
logger_logs, checker_logs = [], []
streamerlist = {}
with open(path_to_settings, "r") as file:
for streamer_ifc in json.load(file)['windows'][0]["tabs"]:
if "data" in streamer_ifc["splits2"]:
stremaer = streamer_ifc["splits2"]["data"]["name"]
dbinf = db["streamers"].find_one({"name": stremaer})
following_streamers.append(stremaer)
if dbinf is None:
streamerlist[stremaer] = {"logfiles": {}}
adding_status = addtodb_streamer(stremaer, *(getstreamerinfo(stremaer))[:-1])
if type(adding_status) is str:
preStartExceptions.append(adding_status)
else:
streamerlist[stremaer] = {"logfiles": dbinf["logfiles"]}
else:
preStartExceptions.append("Exception: Пустые вкладки в Chatterino.")
break
if preStartExceptions:
fatal = False
for Exception_ifc in preStartExceptions:
if "Не найдена папка с логами" not in Exception_ifc:
fatal = True
GUI.print_logger(Exception_ifc)
if fatal:
GUI.print_logger("Fatal: Запуcк невозможен.")
loop = False
elif not preStartExceptions and preStartInfo:
for Info_ifc in preStartInfo:
GUI.print_logger(Info_ifc)
GUI.print_logger(f"Info: Собираем логи от: {', '.join(following_streamers)}.")
GUI.print_logger("Starting: Запуcкаем логгер.")
GUI.print_checker("$TYPE$Starting$TYPE$$MESS$Запускаем чеккер.$MESS$")
GUI.print_checker("$TYPE$Info$TYPE$$MESS$Слушаем https://cyberinquisitor414.glitch.me/LOGWIEWIERdb.$MESS$")
if loop:
GUI.after(500, func=logs_to_console)
logger_thread.start()
checker_thread.start()
GUI.protocol('WM_DELETE_WINDOW', withdraw_window)
GUI.mainloop()