From c9431139dcf6918c2e128d0e7cb79277e1c4a216 Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Wed, 23 Nov 2016 11:55:57 +0000 Subject: [PATCH] Send ship links to EDSM --- EDMarketConnector.py | 25 +++++++++++++++++++------ README.md | 4 ++-- companion.py | 1 - edsm.py | 7 ++++--- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 32b06ed6..64216d18 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -378,7 +378,7 @@ class AppWindow: self.status['text'] = _("What are you flying?!") # Shouldn't happen elif monitor.cmdr and data['commander']['name'] != monitor.cmdr: raise companion.CredentialsError() # Companion API credentials don't match Journal - elif (auto_update and not data['commander'].get('docked')) or (monitor.system and data['lastSystem']['name'] != monitor.system) or (monitor.shiptype and data['ship']['name'].lower() != monitor.shiptype): + elif (auto_update and not data['commander'].get('docked')) or (monitor.system and data['lastSystem']['name'] != monitor.system) or (monitor.shipid and data['ship']['id'] != monitor.shipid) or (monitor.shiptype and data['ship']['name'].lower() != monitor.shiptype): raise companion.ServerLagging() else: @@ -465,12 +465,25 @@ class AppWindow: if data['commander'].get('credits') is not None: monitor.credits = (data['commander']['credits'], data['commander'].get('debt', 0)) self.edsm.setcredits(monitor.credits) - if monitor.shippaint is None: # paintjob only reported in Journal on change + ship = companion.ship(data) + if ship == self.edsm.lastship: + props = [] + else: + props = [ + ('cargoCapacity', ship['cargo']['capacity']), + ('fuelMainCapacity', ship['fuel']['main']['capacity']), + ('linkToCoriolis', coriolis.url(data)), + ('linkToEDShipyard', edshipyard.url(data)), + ] + if monitor.shippaint is None: + # Companion API server can lag, so prefer Journal. But paintjob only reported in Journal on change. monitor.shipid = data['ship']['id'] monitor.shiptype = data['ship']['name'].lower() monitor.shippaint = data['ship']['modules']['PaintJob'] and data['ship']['modules']['PaintJob']['module']['name'].lower() or '' - self.edsm.updateship(monitor.shipid, monitor.shiptype, 'paintJob', monitor.shippaint) - + props.append(('paintJob', monitor.shippaint)) + if props: + self.edsm.updateship(monitor.shipid, monitor.shiptype, props) + self.edsm.lastship = ship except Exception as e: # Not particularly important so silent on failure if __debug__: print_exc() @@ -557,13 +570,13 @@ class AppWindow: # Send ship info to EDSM on startup or change if entry['event'] in [None, 'LoadGame', 'ShipyardNew', 'ShipyardSwap']: self.edsm.setshipid(monitor.shipid) - self.edsm.updateship(monitor.shipid, monitor.shiptype, 'paintJob', monitor.shippaint) + self.edsm.updateship(monitor.shipid, monitor.shiptype, monitor.shippaint and [('paintJob', monitor.shippaint)] or []) elif entry['event'] in ['ShipyardBuy', 'ShipyardSell']: self.edsm.sellship(entry.get('SellShipID')) # Send paintjob info to EDSM on change if entry['event'] in ['ModuleBuy', 'ModuleSell'] and entry['Slot'] == 'PaintJob': - self.edsm.updateship(monitor.shipid, monitor.shiptype, 'paintJob', monitor.shippaint) + self.edsm.updateship(monitor.shipid, monitor.shiptype, [('paintJob', monitor.shippaint)]) # Write EDSM log on change if monitor.mode and entry['event'] in ['Location', 'FSDJump']: diff --git a/README.md b/README.md index 28506260..af65120f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This app downloads your Cmdr's data, system, scan and station data from the game * sends the station commodity market prices, other station data and system and scan data to the [Elite Dangerous Data Network](https://github.com/jamesremuscat/EDDN/wiki) (“EDDN”) from where you and others can use it via online trading, prospecting and shopping tools such as [eddb](http://eddb.io/), [Elite Trade Net](http://etn.io/), [Inara](http://inara.cz), [ED-TD](http://ed-td.space/), [Thrudd's Trading Tools](http://www.elitetradingtool.co.uk/), [Roguey's](http://roguey.co.uk/elite-dangerous/), etc. * saves the station commodity market prices to files on your computer that you can load into trading tools such as [Trade Dangerous](https://bitbucket.org/kfsone/tradedangerous/wiki/Home), [Thrudd's Trading Tools](http://www.elitetradingtool.co.uk/), [Inara](http://inara.cz), [mEDI's Elite Tools](https://github.com/mEDI-S/mEDI_s-Elite-Tools), etc. * saves a record of your ship loadout to files on your computer that you can load into outfitting tools such as [E:D Shipyard](http://www.edshipyard.com), [Coriolis](http://coriolis.io) or [Elite Trade Net](http://etn.io/). -* sends your flight log to [Elite: Dangerous Star Map](http://www.edsm.net/). +* sends your ship details and flight log to [Elite: Dangerous Star Map](http://www.edsm.net/). You can run the app on the same machine on which you're running Elite: Dangerous or on another machine connected via a network share. @@ -83,7 +83,7 @@ Some options work by reading the Elite: Dangerous game's “journal” files. If ### EDSM -You can send a record of your location to [Elite: Dangerous Star Map](http://www.edsm.net/) where you can view your flight log under My account → Exploration Logs and optionally add private comments about a system. You will need to register for an account and then follow the “[Elite Dangerous Star Map credentials](http://www.edsm.net/settings/api)” link to obtain your API key. +You can send a record of your ship and location to [Elite: Dangerous Star Map](http://www.edsm.net/) where you can view your fleet and flight log, and optionally add private comments about systems. You will need to register for an account and then follow the “[Elite Dangerous Star Map credentials](http://www.edsm.net/settings/api)” link to obtain your API key. Uninstall diff --git a/companion.py b/companion.py index bfbec90b..97ffa6a7 100644 --- a/companion.py +++ b/companion.py @@ -370,7 +370,6 @@ def ship(data): ('free',), ('fuel', 'main', 'capacity'), ('fuel', 'reserve', 'capacity'), - ('fuel', 'superchargedFSD'), ('id',), ('name',), ('value', 'hull'), diff --git a/edsm.py b/edsm.py index 7cdae659..e6114e4c 100644 --- a/edsm.py +++ b/edsm.py @@ -68,6 +68,7 @@ class EDSM: self.result = { 'img': None, 'url': None, 'done': True } self.syscache = set() # Cache URLs of systems with known coordinates self.session = Session() + self.lastship = None # Description of last ship that we sent to EDSM # Can't be in class definition since can only call PhotoImage after window is created EDSM._IMG_KNOWN = tk.PhotoImage(data = 'R0lGODlhEAAQAMIEAFWjVVWkVWS/ZGfFZ////////////////yH5BAEKAAQALAAAAAAQABAAAAMvSLrc/lAFIUIkYOgNXt5g14Dk0AQlaC1CuglM6w7wgs7rMpvNV4q932VSuRiPjQQAOw==') # green circle @@ -211,11 +212,11 @@ class EDSM: if shipid is not None: self.call('api-commander-v1/set-ship-id', '&shipId=%d' % shipid) - def updateship(self, shipid, shiptype, slot = None, thing = None): + def updateship(self, shipid, shiptype, props=[]): if shipid is not None and shiptype: args = '&shipId=%d&type=%s' % (shipid, shiptype) - if slot and thing is not None: - args += '&%s=%s' % (slot, thing) + for (slot, thing) in props: + args += '&%s=%s' % (slot, urllib2.quote(unicode(thing))) self.call('api-commander-v1/update-ship', args) def sellship(self, shipid):