Export fitting to EVE, fix json bugs, and include forgotten CREST service.
This commit is contained in:
@@ -3,6 +3,7 @@ import service
|
||||
import gui.display as d
|
||||
from eos.types import Cargo
|
||||
from eos.db import getItem
|
||||
import json
|
||||
|
||||
class CrestFittings(wx.Frame):
|
||||
|
||||
@@ -64,6 +65,61 @@ class CrestFittings(wx.Frame):
|
||||
self.fitTree.populateSkillTree(fittings)
|
||||
|
||||
|
||||
class ExportToEve(wx.Frame):
|
||||
|
||||
def __init__(self, parent):
|
||||
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition, size=(wx.Size(500,100)), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
|
||||
|
||||
self.mainFrame = parent
|
||||
self.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE))
|
||||
|
||||
sCrest = service.Crest.getInstance()
|
||||
|
||||
self.charChoice = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, [])
|
||||
chars = sCrest.getCrestCharacters()
|
||||
for char in chars:
|
||||
self.charChoice.Append(char.name, char.ID)
|
||||
|
||||
mainSizer = wx.BoxSizer( wx.HORIZONTAL )
|
||||
self.charChoice.SetSelection(0)
|
||||
|
||||
mainSizer.Add( self.charChoice, 1, wx.ALL, 5 )
|
||||
self.exportBtn = wx.Button( self, wx.ID_ANY, u"Export Fit", wx.DefaultPosition, wx.DefaultSize, 5 )
|
||||
mainSizer.Add( self.exportBtn, 0, wx.ALL, 5 )
|
||||
|
||||
self.exportBtn.Bind(wx.EVT_BUTTON, self.exportFitting)
|
||||
|
||||
self.statusbar = wx.StatusBar(self)
|
||||
self.statusbar.SetFieldsCount(2)
|
||||
self.statusbar.SetStatusWidths([100, -1])
|
||||
|
||||
|
||||
self.SetSizer(mainSizer)
|
||||
self.SetStatusBar(self.statusbar)
|
||||
self.Layout()
|
||||
|
||||
self.Centre(wx.BOTH)
|
||||
|
||||
def getActiveCharacter(self):
|
||||
selection = self.charChoice.GetCurrentSelection()
|
||||
return self.charChoice.GetClientData(selection) if selection is not None else None
|
||||
|
||||
def exportFitting(self, event):
|
||||
self.statusbar.SetStatusText("", 0)
|
||||
self.statusbar.SetStatusText("Sending request and awaiting response", 1)
|
||||
sCrest = service.Crest.getInstance()
|
||||
|
||||
sFit = service.Fit.getInstance()
|
||||
data = sFit.exportCrest(self.mainFrame.getActiveFit())
|
||||
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:
|
||||
self.statusbar.SetStatusText("", 1)
|
||||
|
||||
class FittingsTreeView(wx.Panel):
|
||||
def __init__(self, parent):
|
||||
wx.Panel.__init__ (self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, style=wx.TAB_TRAVERSAL)
|
||||
|
||||
@@ -44,7 +44,7 @@ from gui.multiSwitch import MultiSwitch
|
||||
from gui.statsPane import StatsPane
|
||||
from gui.shipBrowser import ShipBrowser, FitSelected, ImportSelected, Stage3Selected
|
||||
from gui.characterEditor import CharacterEditor, SaveCharacterAs
|
||||
from gui.crestFittings import CrestFittings
|
||||
from gui.crestFittings import CrestFittings, ExportToEve
|
||||
from gui.characterSelection import CharacterSelection
|
||||
from gui.patternEditor import DmgPatternEditorDlg
|
||||
from gui.resistsEditor import ResistsEditorDlg
|
||||
@@ -418,6 +418,8 @@ class MainFrame(wx.Frame):
|
||||
self.Bind(wx.EVT_MENU, self.revertChar, id = menuBar.revertCharId)
|
||||
# Browse fittings
|
||||
self.Bind(wx.EVT_MENU, self.eveFittings, id = menuBar.eveFittingsId)
|
||||
# Export to EVE
|
||||
self.Bind(wx.EVT_MENU, self.exportToEve, id = menuBar.exportToEveId)
|
||||
|
||||
#Clipboard exports
|
||||
self.Bind(wx.EVT_MENU, self.exportToClipboard, id=wx.ID_COPY)
|
||||
@@ -486,6 +488,10 @@ class MainFrame(wx.Frame):
|
||||
dlg=CrestFittings(self)
|
||||
dlg.Show()
|
||||
|
||||
def exportToEve(self, event):
|
||||
dlg=ExportToEve(self)
|
||||
dlg.Show()
|
||||
|
||||
def saveChar(self, event):
|
||||
sChr = service.Character.getInstance()
|
||||
charID = self.charSelection.getActiveCharacter()
|
||||
|
||||
@@ -41,6 +41,7 @@ class MainMenuBar(wx.MenuBar):
|
||||
self.saveCharAsId = wx.NewId()
|
||||
self.revertCharId = wx.NewId()
|
||||
self.eveFittingsId = wx.NewId()
|
||||
self.exportToEveId = wx.NewId()
|
||||
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
|
||||
@@ -106,8 +107,8 @@ class MainMenuBar(wx.MenuBar):
|
||||
# CREST Menu
|
||||
crestMenu = wx.Menu()
|
||||
self.Append(crestMenu, "&CREST")
|
||||
eveFittings = wx.MenuItem(crestMenu, self.eveFittingsId, "Browse EVE Fittings")
|
||||
crestMenu.AppendItem(eveFittings)
|
||||
crestMenu.Append(self.eveFittingsId, "Browse EVE Fittings")
|
||||
crestMenu.Append(self.exportToEveId, "Export To EVE")
|
||||
|
||||
# Help menu
|
||||
helpMenu = wx.Menu()
|
||||
|
||||
34
service/crest.py
Normal file
34
service/crest.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import eos.db
|
||||
import config
|
||||
|
||||
class Crest():
|
||||
|
||||
_instance = None
|
||||
@classmethod
|
||||
def getInstance(cls):
|
||||
if cls._instance == None:
|
||||
cls._instance = Crest()
|
||||
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
|
||||
pass
|
||||
|
||||
def getCrestCharacters(self):
|
||||
return eos.db.getCrestCharacters()
|
||||
|
||||
def getCrestCharacter(self, charID):
|
||||
return eos.db.getCrestCharacter(charID)
|
||||
|
||||
def getFittings(self, charID):
|
||||
char = self.getCrestCharacter(charID)
|
||||
char.auth()
|
||||
return char.eve.get('https://api-sisi.testeveonline.com/characters/%d/fittings/'%char.ID)
|
||||
|
||||
def postFitting(self, charID, json):
|
||||
char = self.getCrestCharacter(charID)
|
||||
char.auth()
|
||||
print char.eve.token
|
||||
res = char.eve._session.post('https://api-sisi.testeveonline.com/characters/%d/fittings/'%char.ID, data=json)
|
||||
return res
|
||||
@@ -59,8 +59,8 @@ 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'] = "%stypes/%d/"%(eve._endpoint, ofit.ship.item.ID)
|
||||
fit['ship']['id'] = 0
|
||||
fit['ship']['href'] = "%stypes/%d/"%(eve._authed_endpoint, ofit.ship.item.ID)
|
||||
fit['ship']['id'] = ofit.ship.item.ID
|
||||
fit['ship']['name'] = ''
|
||||
|
||||
fit['description'] = "<pyfa:%d />"%ofit.ID
|
||||
@@ -78,21 +78,18 @@ class Port(object):
|
||||
# Order of subsystem matters based on this attr. See GH issue #130
|
||||
slot = int(module.getModifiedItemAttr("subSystemSlot"))
|
||||
item['flag'] = slot
|
||||
item['quantity'] = 1
|
||||
item['type']['href'] = "%stypes/%d/"%(eve._endpoint, module.item.ID)
|
||||
item['type']['id'] = 0
|
||||
item['type']['name'] = ''
|
||||
else:
|
||||
if not slot in slotNum:
|
||||
slotNum[slot] = INV_FLAGS[slot]
|
||||
|
||||
item['flag'] = slotNum[slot]
|
||||
item['quantity'] = 1
|
||||
item['type']['href'] = "%stypes/%d/"%(eve._endpoint, module.item.ID)
|
||||
item['type']['id'] = 0
|
||||
item['type']['name'] = ''
|
||||
|
||||
slotNum[slot] += 1
|
||||
|
||||
item['quantity'] = 1
|
||||
item['type']['href'] = "%stypes/%d/"%(eve._authed_endpoint, module.item.ID)
|
||||
item['type']['id'] = module.item.ID
|
||||
item['type']['name'] = ''
|
||||
|
||||
fit['items'].append(item)
|
||||
|
||||
return json.dumps(fit)
|
||||
|
||||
Reference in New Issue
Block a user