Skip to content

Commit

Permalink
Send ship links to EDSM
Browse files Browse the repository at this point in the history
  • Loading branch information
Marginal committed Nov 23, 2016
1 parent 8bb09cc commit c943113
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
25 changes: 19 additions & 6 deletions EDMarketConnector.py
Expand Up @@ -378,7 +378,7 @@ def getandsend(self, event=None, retrying=False):
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:
Expand Down Expand Up @@ -465,12 +465,25 @@ def getandsend(self, event=None, retrying=False):
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()
Expand Down Expand Up @@ -557,13 +570,13 @@ def journal_event(self, event):
# 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']:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion companion.py
Expand Up @@ -370,7 +370,6 @@ def addleaf(data, to, props):
('free',),
('fuel', 'main', 'capacity'),
('fuel', 'reserve', 'capacity'),
('fuel', 'superchargedFSD'),
('id',),
('name',),
('value', 'hull'),
Expand Down
7 changes: 4 additions & 3 deletions edsm.py
Expand Up @@ -68,6 +68,7 @@ def __init__(self):
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
Expand Down Expand Up @@ -211,11 +212,11 @@ def setshipid(self, shipid):
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):
Expand Down

0 comments on commit c943113

Please sign in to comment.