forked from Eve-PySpy/PySpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
102 lines (89 loc) · 3.29 KB
/
__main__.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
# !/usr/local/bin/python3.6
# MIT licensed
# Copyright (c) 2018 White Russsian
# Github: <https://github.com/Eve-PySpy/PySpy>**********************
''' This is the primary module responsible for launching a background
thread that watches for changes in the clipboard and if it detects a
list of strings that could be EVE Online character strings, sends them
to the analyze.py module to gather specific information from CCP's ESI
API and zKIllboard's API. This information then gets sent to the GUI for
output.
'''
# **********************************************************************
import logging
import re
import threading
import time
import os
import wx
import pyperclip
import analyze
import config
import gui
import statusmsg
import db
# cSpell Checker - Correct Words****************************************
# // cSpell:words russsian, ccp's, pyperclip, chkversion, clpbd, gui
# **********************************************************************
Logger = logging.getLogger(__name__)
# Example call: Logger.info("Something badhappened", exc_info=True) ****
def watch_clpbd():
valid = False
recent_value = None
while True:
clipboard = pyperclip.paste()
if clipboard != recent_value:
char_names = clipboard.splitlines()
for name in char_names:
valid = check_name_validity(name)
if valid is False:
break
if valid:
statusmsg.push_status("Clipboard change detected...")
recent_value = clipboard
analyze_chars(clipboard.splitlines())
time.sleep(0.5) # Short sleep between loops to reduce CPU load
def check_name_validity(char_name):
if len(char_name) < 3:
return False
regex = r"[^ 'a-zA-Z0-9-]" # Valid EVE Online character names
if re.search(regex, char_name):
return False
return True
def analyze_chars(char_names):
conn_mem, cur_mem = db.connect_memory_db()
conn_dsk, cur_dsk = db.connect_persistent_db()
start_time = time.time()
wx.CallAfter(app.PySpy.grid.ClearGrid)
try:
outlist = analyze.main(char_names, conn_mem, cur_mem, conn_dsk, cur_dsk)
duration = round(time.time() - start_time, 1)
if outlist is not None:
# Need to use keyword args as sortOutlist can also get called
# by event handler which would pass event object as first argument.
wx.CallAfter(
app.PySpy.sortOutlist,
outlist=outlist,
duration=duration
)
else:
statusmsg.push_status(
"No valid character names found. Please try again..."
)
except Exception:
Logger.error(
"Failed to collect character information. Clipboard "
"content was: " + str(char_names), exc_info=True
)
os.environ["WXSUPPRESS_SIZER_FLAGS_CHECK"] = "1"
try:
app = gui.App(0) # Has to be defined before background thread starts.
background_thread = threading.Thread(
target=watch_clpbd,
daemon=True
)
background_thread.start()
app.MainLoop()
except SystemExit:
Logger.info("PySpy has been terminated.")
os.exit(0)