Get ESI fitting import working completely. Use a file cache for EsiApp to prevent long startup times (possibly cache for about a week or so, and start in background if it needs to be gotten again?)
This commit is contained in:
@@ -134,9 +134,9 @@ class CrestFittings(wx.Frame):
|
||||
try:
|
||||
waitDialog = wx.BusyInfo("Fetching fits, please wait...", parent=self)
|
||||
fittings = sCrest.getFittings(self.getActiveCharacter())
|
||||
self.cacheTime = fittings.get('cached_until')
|
||||
self.updateCacheStatus(None)
|
||||
self.cacheTimer.Start(1000)
|
||||
# self.cacheTime = fittings.get('cached_until')
|
||||
# self.updateCacheStatus(None)
|
||||
# self.cacheTimer.Start(1000)
|
||||
self.fitTree.populateSkillTree(fittings)
|
||||
del waitDialog
|
||||
except requests.exceptions.ConnectionError:
|
||||
@@ -385,11 +385,12 @@ class FittingsTreeView(wx.Panel):
|
||||
tree.DeleteChildren(root)
|
||||
|
||||
dict = {}
|
||||
fits = data['items']
|
||||
fits = data
|
||||
for fit in fits:
|
||||
if fit['ship']['name'] not in dict:
|
||||
dict[fit['ship']['name']] = []
|
||||
dict[fit['ship']['name']].append(fit)
|
||||
ship = getItem(fit['ship_type_id'])
|
||||
if ship.name not in dict:
|
||||
dict[ship.name ] = []
|
||||
dict[ship.name ].append(fit)
|
||||
|
||||
for name, fits in dict.items():
|
||||
shipID = tree.AppendItem(root, name)
|
||||
@@ -412,7 +413,7 @@ class FittingsTreeView(wx.Panel):
|
||||
|
||||
for item in fit['items']:
|
||||
try:
|
||||
cargo = Cargo(getItem(item['type']['id']))
|
||||
cargo = Cargo(getItem(item['type_id']))
|
||||
cargo.amount = item['quantity']
|
||||
list.append(cargo)
|
||||
except Exception as e:
|
||||
|
||||
@@ -166,8 +166,6 @@ 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)
|
||||
|
||||
|
||||
@@ -50,15 +50,6 @@ 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',
|
||||
@@ -73,15 +64,14 @@ class Crest(object):
|
||||
|
||||
@classmethod
|
||||
def initEsiApp(cls):
|
||||
with Timer() as t:
|
||||
cls.esiapp = EsiApp(cache=None)
|
||||
|
||||
with Timer() as t:
|
||||
with Timer("Main EsiApp") as t:
|
||||
cls.esiapp = EsiApp(cache=file_cache)
|
||||
with Timer('ESI v1') as t:
|
||||
cls.esi_v1 = cls.esiapp.get_v1_swagger
|
||||
with Timer() as t:
|
||||
with Timer('ESI v4') as t:
|
||||
cls.esi_v4 = cls.esiapp.get_v4_swagger
|
||||
|
||||
esiRdy.set()
|
||||
# esiRdy.set()
|
||||
|
||||
@classmethod
|
||||
def genEsiClient(cls, security=None):
|
||||
@@ -118,10 +108,12 @@ class Crest(object):
|
||||
mode. The mode is sent as an argument, as well as the umber of
|
||||
characters still in the cache (if USER mode)
|
||||
"""
|
||||
Crest.initEsiApp()
|
||||
|
||||
prefetch = EsiInitThread()
|
||||
prefetch.daemon = True
|
||||
prefetch.start()
|
||||
|
||||
# prefetch = EsiInitThread()
|
||||
# prefetch.daemon = True
|
||||
# prefetch.start()
|
||||
|
||||
self.settings = CRESTSettings.getInstance()
|
||||
self.scopes = ['characterFittingsRead', 'characterFittingsWrite']
|
||||
@@ -188,7 +180,7 @@ class Crest(object):
|
||||
character_id=charID
|
||||
)
|
||||
resp = char.esi_client.request(op)
|
||||
return resp
|
||||
return resp.data
|
||||
|
||||
def postFitting(self, charID, json):
|
||||
# @todo: new fitting ID can be recovered from Location header,
|
||||
|
||||
@@ -491,7 +491,7 @@ class Port(object):
|
||||
|
||||
# If JSON-style start, parse as CREST/JSON
|
||||
if firstLine[0] == '{':
|
||||
return "JSON", (cls.importCrest(string),)
|
||||
return "JSON", (cls.importESI(string),)
|
||||
|
||||
# If we've got source file name which is used to describe ship name
|
||||
# and first line contains something like [setup name], detect as eft config file
|
||||
@@ -509,7 +509,7 @@ class Port(object):
|
||||
return "DNA", (cls.importDna(string),)
|
||||
|
||||
@staticmethod
|
||||
def importCrest(str_):
|
||||
def importESI(str_):
|
||||
|
||||
sMkt = Market.getInstance()
|
||||
fitobj = Fit()
|
||||
@@ -521,11 +521,11 @@ class Port(object):
|
||||
fitobj.notes = refobj['description']
|
||||
|
||||
try:
|
||||
refobj = refobj['ship']['id']
|
||||
ship = refobj['ship_type_id']
|
||||
try:
|
||||
fitobj.ship = Ship(sMkt.getItem(refobj))
|
||||
fitobj.ship = Ship(sMkt.getItem(ship))
|
||||
except ValueError:
|
||||
fitobj.ship = Citadel(sMkt.getItem(refobj))
|
||||
fitobj.ship = Citadel(sMkt.getItem(ship))
|
||||
except:
|
||||
pyfalog.warning("Caught exception in importCrest")
|
||||
return None
|
||||
@@ -535,7 +535,7 @@ class Port(object):
|
||||
moduleList = []
|
||||
for module in items:
|
||||
try:
|
||||
item = sMkt.getItem(module['type']['id'], eager="group.category")
|
||||
item = sMkt.getItem(module['type_id'], eager="group.category")
|
||||
if module['flag'] == INV_FLAG_DRONEBAY:
|
||||
d = Drone(item)
|
||||
d.amount = module['quantity']
|
||||
|
||||
Reference in New Issue
Block a user