-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPUSI.pyw
473 lines (374 loc) · 14.6 KB
/
PUSI.pyw
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
# PUSI.py
# Python User Servicing Interface
# Controller script to PENIS and BALLS
# AFK away and listen for a ding.
#
# Written in python for you Alex....
#
# Copyright (c) 2015, QQHeresATissue <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
###############################################################################
from time import gmtime
import time
from threading import *
import sys
import os
from os.path import expanduser
from datetime import datetime, timedelta, date
import re
import platform
import json
# Do initial checks, code taken from Pyfa... cause that shit rocks
if sys.version_info < (2,6) or sys.version_info > (3,0):
print("PUSI requires python 2.7\nExiting.")
time.sleep(10)
sys.exit(1)
try:
import wxversion
except ImportError:
print("Cannot find wxPython\nYou can download wxPython (2.8) from http://www.wxpython.org/")
time.sleep(10)
sys.exit(1)
try:
wxversion.select('2.8')
except wxversion.VersionError:
try:
wxversion.ensureMinimal('2.8')
except wxversion.VersionError:
print("Installed wxPython version doesn't meet requirements.\nYou can download wxPython (2.8) from http://www.wxpython.org/")
time.sleep(10)
sys.exit(1)
else:
print("wxPython 2.8 not found; attempting to use newer version, expect errors")
import wx
import wx.media
# suppress nerd speak
sys.tracebacklimit = 0
# set a version
ver = "0.6.1b"
ID_PENIS_START = wx.NewId()
ID_BALLS_START = wx.NewId()
# Get current working direcroty
pusi_dir = os.path.dirname(__file__)
# Set wav names
hostile_sound = os.path.join( pusi_dir, "sounds", "hostile.wav")
done_sound = os.path.join( pusi_dir, "sounds", "sites_done.wav")
tags_and_ammo = os.path.join ( pusi_dir, "sounds", "cash_money.wav")
# Are we on windows or linux?
which_os = platform.system()
if which_os == "Windows":
import winsound
from winsound import PlaySound, SND_FILENAME
# Setup a class for text redirection
class RedirectText(object):
def __init__(self,aWxTextCtrl):
self.out=aWxTextCtrl
# Write string to wx window
def write(self,string):
wx.CallAfter(self.out.AppendText, string)
# Main form for graphical PUSI
class pusi(wx.Frame):
def __init__(self,parent,id):
# Create the main window with the title PUSI <version number>
wx.Frame.__init__(self,parent,id,'PUSI %s' % ver, size=(800,340), style = wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX))
#
self.Bind(wx.EVT_CLOSE, self.Close)
# Create a panel in the windows
self.panel = wx.Panel(self)
# Setup logging early so we see it in the panel
logbox = wx.TextCtrl(self.panel, wx.ID_ANY, size = (780, 290), pos = (10,40), style = wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL)
# Redirect all printed messages to the panel
redir=RedirectText(logbox)
sys.stdout=redir
sys.stderr=redir
# Create a start and stop button
self.penis_start = wx.Button(self.panel, ID_PENIS_START, label="Start PENIS", pos=(530,10), size=(90,25))
self.balls_start = wx.Button(self.panel, ID_BALLS_START, label="Start BALLS", pos=(10, 10), size=(90,25))
# Define regions we have systems for in a list
region_list = [ 'dek', 'brn', 'ftn', 'fade', 'tnl', 'tri', 'vnl', 'vale' ]
# Create text "Region" before the dropdown box
wx.StaticText(self.panel, -1, 'Region', (105,15))
# Create the dropdown box and use DEK as a default selection
pusi.region_select = wx.ComboBox(self.panel, -1, pos=(150,10), size=(75,25), choices = region_list, style=wx.CB_DROPDOWN)
pusi.region_select.SetSelection(0)
#Create the system input box
wx.StaticText(self.panel, -1, 'System', (230, 15))
pusi.system_select = wx.TextCtrl(self.panel, -1, '', (280,10), (120,-1))
# Create the range input box
range_list = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ]
wx.StaticText(self.panel, -1, 'Range', (410, 15))
pusi.range_select = wx.ComboBox(self.panel, -1, '', pos=(450,10), size=(80,25), choices = range_list, style=wx.CB_DROPDOWN)
pusi.range_select.SetSelection(5)
# Bind button clicks to events (start|stop)
self.Bind(wx.EVT_BUTTON, self.penis_run, id=ID_PENIS_START)
self.Bind(wx.EVT_BUTTON, self.balls_run, id=ID_BALLS_START)
# Set a watch variable to check later. If we want the process to stop, self.watch becomes 1
self.penis_watcher = None
self.balls_watcher = None
# Shameless self adversiting
print "Python User Servicing Interface v%s by QQHeresATissue" % ver
# Setup a functions to start the watcher thread
def penis_run(self, event):
if not self.penis_watcher:
self.penis_watcher = StartPENIS(self)
def balls_run(self, event):
if not self.balls_watcher:
self.balls_watcher = StartBALLS(self)
def Close(self, event):
self.Destroy()
# Define watcher thread
class StartPENIS(Thread):
def __init__(self, threadID):
Thread.__init__(self)
# Kill the thread when the main process is exited
self.daemon = True
self.threadID = threadID
self._want_abort = 0
self.start()
# setup our log file watcher, only open it once and update when a new line is written
def hostile_watch(self, logfile, region_data):
fp = open(logfile, 'r')
while True:
# remove null padding (lol ccp)
new = re.sub(r'[^\x20-\x7e]', '', fp.readline())
if new:
relevant_system = self.find_system_in_string(new, region_data)
if relevant_system:
yield (relevant_system, new)
else:
time.sleep(0.01)
# Start the main thread for alerting
def run(self):
print "Starting the Potentially Erroneous Nullsec Intelligence System"
if which_os == "Linux":
# Wine default path
hostile_logdir = os.path.join( expanduser("~"), "EVE", "logs", "Chatlogs" )
elif which_os == "Windows":
# Win 7 default log path
hostile_logdir = os.path.join( expanduser("~"), "Documents", "EVE", "logs", "Chatlogs" )
elif which_os == "Darwin":
# OSX default log path
hostile_logdir = os.path.join( expanduser("~"), "Library", "Application Support", "EVE Online", "p_drive", "User", "My Documents", "EVE", "logs", "Chatlogs" )
else:
print "What fucking OS are you running?"
# get region based on our dropdown box selection
region = pusi.region_select.GetValue()
# get the system based on our system input
system = pusi.system_select.GetValue()
# select identified logs and sort by date
hostile_tmp = sorted([ f for f in os.listdir(hostile_logdir) if f.startswith("%s.imperium" % str(region))])
# testing line so we shit up Corp chat not intel chans
# hostile_tmp = sorted([ f for f in os.listdir(hostile_logdir) if f.startswith('Corp')])
# grab the most recent file for each log
logfile = os.path.join( hostile_logdir, hostile_tmp[-1] )
# triggers to look for in the intel channels. Read from json files for a specified system
# big thanks to Orestus for getting the branch systems together and suggesting the change!!
# Support expanded by Narex Vivari
json_data = open(os.path.join( pusi_dir, "regions", "%s.json" % str(region)))
region_data = json.load(json_data)
json_data.close()
# ignore status requests and clr reports
status_words = [ "status", \
"Status", \
"clear", \
"Clear", \
"stat", \
"Stat", \
"clr", \
"Clr",
"EVE System" ]
# Print some initial info lines
print "parsing from - Intel: %s\n" % (hostile_tmp[-1])
# if the word matches a trigger, move on
for related_system, hostile_hit_sentence in self.hostile_watch(logfile, region_data):
#print "%r | %r | %r | %r" % (related_system, self.hostile_words, hostile_hit_sentence)
# if someone is just asking for status, ignore the hit
if not any(status_word in hostile_hit_sentence for status_word in status_words):
# find distance to the reported system
distance = self.find_system_distance(system, related_system, region_data, int(pusi.range_select.GetValue()))
if distance != None:
# get the current time for each event
hit_time = time.strftime('%H:%M:%S')
# get current date/time in UTC
utc = time.strftime('[ %Y.%m.%d %H:%M', gmtime())[:17]
# print the alert
if which_os == "Windows":
print "%s - PENIS INTEL ALERT!!\n" % (hit_time)
print "%r (%s jumps)\n" % (hostile_hit_sentence, distance)
wx.Yield()
else:
print "%s - PENIS INTEL ALERT!!" % (hit_time)
print "%r (%s jumps)\n" % (hostile_hit_sentence, distance)
wx.Yield()
# play a tone to get attention, only if its recent!
if utc in hostile_hit_sentence:
if which_os == "Linux":
os.system("aplay -q %r" % hostile_sound)
elif which_os == "Windows":
winsound.PlaySound("%s" % hostile_sound,SND_FILENAME)
elif which_os == "Darwin":
print('\a')
print('\a')
print('\a')
def find_system_in_string(self, string, region_data):
for system in region_data:
if system['name'] in string:
return system['name']
return None
def find_system_distance(self, start_system, dest_system, region_data, range):
routes_found = []
# find the distance of all routes from start system to destination system
self.system_distance_recursive(start_system, dest_system, region_data, 0, range, [], routes_found)
# return shortest path
return min(routes_found) if len(routes_found) else None
def system_distance_recursive(self, cur_system, dest_system, region_data, distance, range, checked, routes_found):
# exit if out of range or system is already checked
if distance > range or cur_system in checked:
return
if cur_system == dest_system:
# destination found, so we don't need to check further connections
routes_found.append(distance)
return
for connected_system in self.get_connected_systems(cur_system, region_data):
# duplicate existing path and append this system
now_checked = list(checked)
now_checked.append(cur_system)
# recursively find distance, if a path exists
conn_dist = self.system_distance_recursive(connected_system, dest_system, region_data, distance + 1, range, now_checked, routes_found)
if conn_dist >= 0:
# this system is parth of a path to destination, so add the distance
routes_found.append(conn_dist)
def get_connected_systems(self, system, region_data):
# find the system and return its connections. can easily be optimized using a dict if performance is an issue (which it shouldn't be when only checking regions)
system_data = [x['connections'] for x in region_data if x['name'] == system]
# connections across regions exist in the data, but are currently not supported. but people probably don't report cross-region intel anyway
return system_data[0] if len(system_data) > 0 else []
# Define BALLS watcher thread
class StartBALLS(Thread):
def __init__(self, threadID):
Thread.__init__(self)
# Kill the thread when the main process is exited
self.daemon = True
self.threadID = threadID
self._want_abort = 0
self.start()
# setup our log file watcher, only open it once and update when a new line is written
def balls_watch(self, fn, words):
done_count = 0
fp = open(fn, 'r')
while True:
new = fp.readline()
if new:
done_count = 0
for word in words:
if word in new:
yield (word, new)
else:
done_count = done_count + 1
if done_count > 129:
print "BALLS Notification"
print "%r - Sites done (or something is wrong)\n" % (time.strftime('%H:%M:%S'))
if which_os == "Linux":
os.system("aplay -q %r" % done_sound)
elif which_os == "Windows":
winsound.PlaySound("%s" % done_sound,SND_FILENAME)
elif which_os == "Darwin":
print('\a')
print('\a')
print('\a')
done_count = 0
time.sleep(0.5)
def run(self):
count = 0
if which_os == "Linux":
# Wine default path
logdir = os.path.join( expanduser("~"), "EVE", "logs", "Gamelogs" )
elif which_os == "Windows":
# Win 7 default log path
logdir = os.path.join( expanduser("~"), "Documents", "EVE", "logs", "Gamelogs" )
elif which_os == "Darwin":
# OSX default log path
logdir = os.path.join( expanduser("~"), "Library", "Application Support", "EVE Online", "p_drive", "User", "My Documents", "EVE", "logs", "Chatlogs" )
else:
print "What fucking OS are you running?"
# sort by date
tmp = sorted([ f for f in os.listdir(logdir) if f.startswith('201')])
# grab the most recent file
fn = os.path.join( logdir, tmp[-1] )
print "\nStarting the Background Alert for Lucrative Loot Script"
print "parsing from %s\n" % tmp[-1]
# triggers to look for in the log file
words = [ "Dread Guristas", \
"Dark Blood", \
"True Sansha", \
"Shadow Serpentis", \
"Sentient", \
"Domination",\
"Estamel Tharchon", \
"Vepas Minimala", \
"Thon Eney", \
"Kaikka Peunato", \
"Gotan Kreiss", \
"Hakim Stormare",\
"Mizuro Cybon", \
"Tobias Kruzhor", \
"Ahremen Arkah", \
"Draclira Merlonne", \
"Raysere Giant",\
"Tairei Namazoth", \
"Brokara Ryver", \
"Chelm Soran", \
"Selynne Mardakar", \
"Vizan Ankonin", \
"Brynn Jerdola",\
"Cormack Vaaja", \
"Setele Schellan", \
"Tuvan Orth", \
"Warp scramble attempt" ]
# Don't trigger if we are accepting or getting a contract
false_pos = [ "following items", \
"question" ]
for hit_word, hit_sentence in self.balls_watch(fn, words):
if not any(false_word in hit_sentence for false_word in false_pos):
if count < 1:
count = count + 1
# log the combat lines involving the spawn
print "BALLS ALERT!!"
print "%r - %r\n" % (time.strftime('%H:%M:%S'), hit_word)
wx.Yield()
# debug statement
# print "%r" % (hit_sentence)
# play a tone to get attention
if which_os == "Linux":
os.system("aplay -q %r" % tags_and_ammo)
elif which_os == "Windows":
winsound.PlaySound("%s" % tags_and_ammo,SND_FILENAME)
elif which_os == "Darwin":
print('\a')
print('\a')
print('\a')
else:
print "What fucking system are you running?"
break
elif count == 30:
count = 0
continue
else:
count = count + 1
continue
if __name__ == '__main__':
app=wx.App()
frame=pusi(parent=None,id=-1)
frame.Show()
app.MainLoop()