Implement posting fit to EVE server
This commit is contained in:
@@ -185,17 +185,10 @@ class ExportToEve(wx.Frame):
|
||||
mainSizer = wx.BoxSizer(wx.VERTICAL)
|
||||
hSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
|
||||
if sCrest.settings.get('mode') == CrestModes.IMPLICIT:
|
||||
self.stLogged = wx.StaticText(self, wx.ID_ANY, "Currently logged in as %s" % sCrest.implicitCharacter.name,
|
||||
wx.DefaultPosition, wx.DefaultSize)
|
||||
self.stLogged.Wrap(-1)
|
||||
|
||||
hSizer.Add(self.stLogged, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
|
||||
else:
|
||||
self.charChoice = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, [])
|
||||
hSizer.Add(self.charChoice, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
|
||||
self.updateCharList()
|
||||
self.charChoice.SetSelection(0)
|
||||
self.charChoice = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, [])
|
||||
hSizer.Add(self.charChoice, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
|
||||
self.updateCharList()
|
||||
self.charChoice.SetSelection(0)
|
||||
|
||||
self.exportBtn = wx.Button(self, wx.ID_ANY, "Export Fit", wx.DefaultPosition, wx.DefaultSize, 5)
|
||||
hSizer.Add(self.exportBtn, 0, wx.ALL, 5)
|
||||
@@ -227,7 +220,7 @@ class ExportToEve(wx.Frame):
|
||||
|
||||
self.charChoice.Clear()
|
||||
for char in chars:
|
||||
self.charChoice.Append(char.name, char.ID)
|
||||
self.charChoice.Append(char.characterName, char.characterID)
|
||||
|
||||
self.charChoice.SetSelection(0)
|
||||
|
||||
@@ -249,11 +242,6 @@ class ExportToEve(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
|
||||
|
||||
@@ -272,16 +260,17 @@ class ExportToEve(wx.Frame):
|
||||
|
||||
try:
|
||||
sFit = Fit.getInstance()
|
||||
data = sPort.exportCrest(sFit.getFit(fitID))
|
||||
data = sPort.exportESI(sFit.getFit(fitID))
|
||||
res = sCrest.postFitting(self.getActiveCharacter(), data)
|
||||
|
||||
self.statusbar.SetStatusText("%d: %s" % (res.status_code, res.reason), 0)
|
||||
try:
|
||||
text = json.loads(res.text)
|
||||
self.statusbar.SetStatusText(text['message'], 1)
|
||||
except ValueError:
|
||||
pyfalog.warning("Value error on loading JSON.")
|
||||
self.statusbar.SetStatusText("", 1)
|
||||
self.statusbar.SetStatusText("", 0)
|
||||
self.statusbar.SetStatusText("", 1)
|
||||
# try:
|
||||
# text = json.loads(res.text)
|
||||
# self.statusbar.SetStatusText(text['message'], 1)
|
||||
# except ValueError:
|
||||
# pyfalog.warning("Value error on loading JSON.")
|
||||
# self.statusbar.SetStatusText("", 1)
|
||||
except requests.exceptions.ConnectionError:
|
||||
msg = "Connection error, please check your internet connection"
|
||||
pyfalog.error(msg)
|
||||
|
||||
@@ -740,7 +740,7 @@ class MainFrame(wx.Frame):
|
||||
|
||||
def clipboardCrest(self):
|
||||
fit = db_getFit(self.getActiveFit())
|
||||
toClipboard(Port.exportCrest(fit))
|
||||
toClipboard(Port.exportESI(fit))
|
||||
|
||||
def clipboardXml(self):
|
||||
fit = db_getFit(self.getActiveFit())
|
||||
|
||||
@@ -187,11 +187,18 @@ class Crest(object):
|
||||
resp = char.esi_client.request(op)
|
||||
return resp.data
|
||||
|
||||
def postFitting(self, charID, json):
|
||||
# @todo: new fitting ID can be recovered from Location header,
|
||||
# ie: Location -> https://api-sisi.testeveonline.com/characters/1611853631/fittings/37486494/
|
||||
def postFitting(self, charID, json_str):
|
||||
# @todo: new fitting ID can be recovered from resp.data,
|
||||
char = self.getSsoCharacter(charID)
|
||||
return char.eve.post('%scharacters/%d/fittings/' % (char.eve._authed_endpoint, char.ID), data=json)
|
||||
|
||||
op = Crest.esi_v1.op['post_characters_character_id_fittings'](
|
||||
character_id=char.characterID,
|
||||
fitting=json.loads(json_str)
|
||||
)
|
||||
|
||||
resp = char.esi_client.request(op)
|
||||
|
||||
return resp.data
|
||||
|
||||
def delFitting(self, charID, fittingID):
|
||||
char = self.getSsoCharacter(charID)
|
||||
|
||||
@@ -381,7 +381,7 @@ class Port(object):
|
||||
"""Service which houses all import/export format functions"""
|
||||
|
||||
@classmethod
|
||||
def exportCrest(cls, ofit, callback=None):
|
||||
def exportESI(cls, ofit, callback=None):
|
||||
# A few notes:
|
||||
# max fit name length is 50 characters
|
||||
# Most keys are created simply because they are required, but bogus data is okay
|
||||
@@ -396,9 +396,7 @@ class Port(object):
|
||||
# max length is 50 characters
|
||||
name = ofit.name[:47] + '...' if len(ofit.name) > 50 else ofit.name
|
||||
fit['name'] = name
|
||||
fit['ship']['href'] = "%sinventory/types/%d/" % (eve._authed_endpoint, ofit.ship.item.ID)
|
||||
fit['ship']['id'] = ofit.ship.item.ID
|
||||
fit['ship']['name'] = ''
|
||||
fit['ship_type_id'] = ofit.ship.item.ID
|
||||
|
||||
# 2017/03/29 NOTE: "<" or "<" is Ignored
|
||||
# fit['description'] = "<pyfa:%d />" % ofit.ID
|
||||
@@ -426,9 +424,7 @@ class Port(object):
|
||||
slotNum[slot] += 1
|
||||
|
||||
item['quantity'] = 1
|
||||
item['type']['href'] = "%sinventory/types/%d/" % (eve._authed_endpoint, module.item.ID)
|
||||
item['type']['id'] = module.item.ID
|
||||
item['type']['name'] = ''
|
||||
item['type_id'] = module.item.ID
|
||||
fit['items'].append(item)
|
||||
|
||||
if module.charge and sFit.serviceFittingOptions["exportCharges"]:
|
||||
@@ -441,36 +437,28 @@ class Port(object):
|
||||
item = nested_dict()
|
||||
item['flag'] = INV_FLAG_CARGOBAY
|
||||
item['quantity'] = cargo.amount
|
||||
item['type']['href'] = "%sinventory/types/%d/" % (eve._authed_endpoint, cargo.item.ID)
|
||||
item['type']['id'] = cargo.item.ID
|
||||
item['type']['name'] = ''
|
||||
item['type_id'] = cargo.item.ID
|
||||
fit['items'].append(item)
|
||||
|
||||
for chargeID, amount in list(charges.items()):
|
||||
item = nested_dict()
|
||||
item['flag'] = INV_FLAG_CARGOBAY
|
||||
item['quantity'] = amount
|
||||
item['type']['href'] = "%sinventory/types/%d/" % (eve._authed_endpoint, chargeID)
|
||||
item['type']['id'] = chargeID
|
||||
item['type']['name'] = ''
|
||||
item['type_id'] = chargeID
|
||||
fit['items'].append(item)
|
||||
|
||||
for drone in ofit.drones:
|
||||
item = nested_dict()
|
||||
item['flag'] = INV_FLAG_DRONEBAY
|
||||
item['quantity'] = drone.amount
|
||||
item['type']['href'] = "%sinventory/types/%d/" % (eve._authed_endpoint, drone.item.ID)
|
||||
item['type']['id'] = drone.item.ID
|
||||
item['type']['name'] = ''
|
||||
item['type_id'] = drone.item.ID
|
||||
fit['items'].append(item)
|
||||
|
||||
for fighter in ofit.fighters:
|
||||
item = nested_dict()
|
||||
item['flag'] = INV_FLAG_FIGHTER
|
||||
item['quantity'] = fighter.amountActive
|
||||
item['type']['href'] = "%sinventory/types/%d/" % (eve._authed_endpoint, fighter.item.ID)
|
||||
item['type']['id'] = fighter.item.ID
|
||||
item['type']['name'] = fighter.item.name
|
||||
item['type_id'] = fighter.item.ID
|
||||
fit['items'].append(item)
|
||||
|
||||
return json.dumps(fit)
|
||||
|
||||
Reference in New Issue
Block a user