From b1729095a0740ffd0bbe6e7a7bcd17a448a46696 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 18 Oct 2015 17:13:19 -0400 Subject: [PATCH] Export fitting to EVE, fix json bugs, and include forgotten CREST service. --- gui/crestFittings.py | 56 ++++++++++++++++++++++++++++++++++++++++++++ gui/mainFrame.py | 8 ++++++- gui/mainMenuBar.py | 5 ++-- service/crest.py | 34 +++++++++++++++++++++++++++ service/port.py | 19 +++++++-------- 5 files changed, 108 insertions(+), 14 deletions(-) create mode 100644 service/crest.py diff --git a/gui/crestFittings.py b/gui/crestFittings.py index 45f2c4df8..581df7839 100644 --- a/gui/crestFittings.py +++ b/gui/crestFittings.py @@ -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) diff --git a/gui/mainFrame.py b/gui/mainFrame.py index d2747626a..377f2c3f8 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -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() diff --git a/gui/mainMenuBar.py b/gui/mainMenuBar.py index 76ea60f75..069437c31 100644 --- a/gui/mainMenuBar.py +++ b/gui/mainMenuBar.py @@ -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() diff --git a/service/crest.py b/service/crest.py new file mode 100644 index 000000000..f77829edd --- /dev/null +++ b/service/crest.py @@ -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 diff --git a/service/port.py b/service/port.py index 14b14fa3c..1cfbbf297 100644 --- a/service/port.py +++ b/service/port.py @@ -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'] = ""%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)