More work on getting fittings form a character via ESI. It's starting to be come a pain working with this client with having to background it until it initializes. Thinking about rolling my own, considering we only need a few calls and not a whole package.

This commit is contained in:
blitzmann
2018-02-07 02:07:42 -05:00
parent eea8019593
commit e77dddc15b
4 changed files with 29 additions and 11 deletions

View File

@@ -35,7 +35,7 @@ class SsoCharacter(object):
@reconstructor
def init(self):
pass
self.esi_client = None
def get_sso_data(self):
""" Little "helper" function to get formated data for esipy security
@@ -44,7 +44,7 @@ class SsoCharacter(object):
'access_token': self.accessToken,
'refresh_token': self.refreshToken,
'expires_in': (
self.accessTokenExpires - datetime.utcnow()
self.accessTokenExpires - datetime.datetime.utcnow()
).total_seconds()
}

View File

@@ -126,11 +126,6 @@ class CrestFittings(wx.Frame):
event.Skip()
def getActiveCharacter(self):
sCrest = Crest.getInstance()
if sCrest.settings.get('mode') == CrestModes.IMPLICIT:
return sCrest.implicitCharacter.ID
selection = self.charChoice.GetCurrentSelection()
return self.charChoice.GetClientData(selection) if selection is not None else None

View File

@@ -166,6 +166,8 @@ class MainFrame(wx.Frame):
i = wx.Icon(BitmapLoader.getBitmap("pyfa", "gui"))
self.SetIcon(i)
sCrest = Crest()
# Create the layout and windows
mainSizer = wx.BoxSizer(wx.HORIZONTAL)

View File

@@ -34,6 +34,9 @@ if not os.path.exists(cache_path):
file_cache = FileCache(cache_path)
esiRdy = threading.Event()
class Servers(Enum):
TQ = 0
SISI = 1
@@ -45,6 +48,17 @@ class CrestModes(Enum):
from utils.timer import Timer
class EsiInitThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.name = "EsiInitThread"
def run(self):
Crest.initEsiApp()
class Crest(object):
clientIDs = {
Servers.TQ : 'f9be379951c046339dc13a00e6be7704',
@@ -67,6 +81,8 @@ class Crest(object):
with Timer() as t:
cls.esi_v4 = cls.esiapp.get_v4_swagger
esiRdy.set()
@classmethod
def genEsiClient(cls, security=None):
return EsiClient(
@@ -103,6 +119,10 @@ class Crest(object):
characters still in the cache (if USER mode)
"""
prefetch = EsiInitThread()
prefetch.daemon = True
prefetch.start()
self.settings = CRESTSettings.getInstance()
self.scopes = ['characterFittingsRead', 'characterFittingsWrite']
@@ -159,15 +179,16 @@ class Crest(object):
char = eos.db.getSsoCharacter(charID, config.getClientSecret())
if char.esi_client is None:
char.esi_client = Crest.genEsiClient()
char.esi_client.security.update_token(char.get_sso_data())
return char
def getFittings(self, charID):
char = self.getSsoCharacter(charID)
op = esi_v1.op['get_characters_character_id_fittings'](
character_id=self.currentCharacter.character_id
op = Crest.esi_v1.op['get_characters_character_id_fittings'](
character_id=charID
)
resp = self.currentCharacter.esi_client.request(op)
return char.eve.get('%scharacters/%d/fittings/' % (char.eve._authed_endpoint, char.ID))
resp = char.esi_client.request(op)
return resp
def postFitting(self, charID, json):
# @todo: new fitting ID can be recovered from Location header,