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