-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRUN.py
More file actions
152 lines (123 loc) · 5.69 KB
/
RUN.py
File metadata and controls
152 lines (123 loc) · 5.69 KB
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
import os
import re
from glob import glob
import colorama
from colorama import Fore, Back, Style
from playsound import playsound
import time
import datetime
####################################################################################################################
#My Classes
class MyIntel:
user = "UNKNWON"
body = "UNKNOWN"
location = "UNKNOWN"
ship = "UNKNOWN"
cyno = "NO "
####################################################################################################################
def getlog():
#Open channel file for logs
file_path = os.path.join(os.path.dirname(__file__),"watchlist_channel.txt")
file = open(file_path)
channel = file.readline()
return channel
####################################################################################################################
def logcheck(prefix):
latest = "log.txt"
found = glob(rf'C:\Users\*\Documents\EVE\logs\Chatlogs\{prefix}*.txt')
if found:
latest = sorted(found)[-1]
with open(rf"{latest}",encoding='utf-16-le') as file:
lines = file.read().splitlines()
file.close()
#Truncating the timestamp from the string
return lines[-1][25:]
####################################################################################################################
def parseintel(intel):
intelobject = MyIntel
#Parse reporter username, split from text body
intelobject.user = intel.split('>')[0]
#Trim blankspace from end of name
intelobject.user = intelobject.user[:-1]
#Parse intel text, split body from user
intelobject.body = intel.split('>')[1]
#Trim blankspace from start of body
intelobject.body = intelobject.body[1:]
intel = intelobject.body
intel = str.lower(intel)
#Open systems file for comparison against intel string
file_path = os.path.join(os.path.dirname(__file__),"watchlist_ships.txt")
file = open(file_path)
#Parse body for ship string, also checks for cyno denotion with asterisk
if "spike" in intel:
intelobject.ship = "!SPIKE"
elif "clr" in intel or "clear" in intel:
intelobject.ship = "!CLEAR"
else:
for x in file:
x = x.rstrip('\n')
if x[-1] == "*":
intelobject.cyno = "YES"
x = x.rstrip('*')
if re.search(rf'\b{str.lower(x)}\b', intel):
intelobject.ship = x
file.close()
break
intelobject.cyno = "NO "
intelobject.ship = "UNKNOWN"
#If a matched ship is not found
file.close()
#Open systems file for comparison against intel string
file_path = os.path.join(os.path.dirname(__file__),"watchlist_systems.txt")
file = open(file_path)
#Parse body for location string
for x in file:
x = x.rstrip('\n')
if re.search(rf'\b{str.lower(x)}\b', intel):
intelobject.location = x
file.close()
return intelobject
#If a matched location is not found
file.close()
intelobject.location = "UNKNOWN"
return intelobject
####################################################################################################################
def output():
#Prevent displaying the first (Last) line in the log, usually not relevent
channel = getlog()
temp_message = logcheck(channel)
intelobject = MyIntel
alert_path = os.path.join(os.path.dirname(__file__),"Alerts","Alert1.mp3")
while 1:
intel = logcheck(channel)
if intel != temp_message:
#Update time
current_time = datetime.datetime.now()
intelobject = parseintel(intel)
if(intelobject.location != "UNKNOWN"):
if intelobject.ship == "!CLEAR":
print(f"{current_time.hour + 7:02}:{current_time.minute:02}:{current_time.second:02} >>> " + Back.GREEN + f"{intelobject.user:<25}{intelobject.location:<12}{intelobject.ship:<12}{intelobject.cyno}")
playsound(alert_path)
else:
print(f"{current_time.hour + 7:02}:{current_time.minute:02}:{current_time.second:02} >>> " + Back.RED + f"{intelobject.user:<25}{intelobject.location:<12}{intelobject.ship:<12}{intelobject.cyno}")
playsound(alert_path)
temp_message = intel
time.sleep(.5)
####################################################################################################################
#Initial Variables
current_time = datetime.datetime.now()
colorama.init(autoreset=True)
####################################################################################################################
#PROGRAM START / Splash Screen Header
print("------------------------------------------------------------------")
print("WatchDog, Created by Harry Kashuken")
print("------------------------------------------------------------------")
print("Time Reporter Name System Ship Cyno")
print("------------------------------------------------------------------")
print(f"{current_time.hour + 7:02}:{current_time.minute:02}:{current_time.second:02} >>> SESSION STARTED")
####################################################################################################################
while 1:
#Update Time every refresh, + 7 modifier to match EVE time
current_time = datetime.datetime.now()
#Consolidated terminal output to a seperate function for organization
output()