1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 08:17:13 +03:00

Send station Shipyard & Outfitting data to EDDN.

This commit is contained in:
Jonathan Harris 2015-06-19 00:32:08 +01:00
parent 9dec5f95ec
commit f57deae3f3
3 changed files with 84 additions and 30 deletions

View File

@ -166,13 +166,14 @@ class AppWindow:
else:
return self.getandsend() # try again
def getandsend(self, event=None):
if time() < self.holdofftime: return # Was invoked by Return key while in cooldown
def getandsend(self, event=None, retrying=False):
self.cmdr['text'] = self.system['text'] = self.station['text'] = ''
self.status['text'] = 'Fetching market data...'
self.button['state'] = tk.DISABLED
self.w.update_idletasks()
if not retrying:
if time() < self.holdofftime: return # Was invoked by Return key while in cooldown
self.cmdr['text'] = self.system['text'] = self.station['text'] = ''
self.status['text'] = 'Fetching station data...'
self.button['state'] = tk.DISABLED
self.w.update_idletasks()
try:
querytime = int(time())
@ -193,6 +194,10 @@ class AppWindow:
self.status['text'] = "Where are you?!" # Shouldn't happen
elif not data.get('ship') or not data['ship'].get('modules') or not data['ship'].get('name','').strip():
self.status['text'] = "What are you flying?!" # Shouldn't happen
elif (config.getint('output') & config.OUT_EDDN) and not data['lastStarport'].get('ships') and not retrying:
# API is flakey about shipyard info - retry if missing
self.w.after(2000, lambda:self.getandsend(retrying=True))
return
else:
# stuff we can do when not docked
if config.getint('output') & config.OUT_LOG:
@ -206,20 +211,27 @@ class AppWindow:
elif not data['commander'].get('docked'):
self.status['text'] = "You're not docked at a station!"
elif not data['lastStarport'].get('commodities'):
self.status['text'] = "Station doesn't have a market!"
else:
if config.getint('output') & config.OUT_CSV:
bpc.export(data, True)
if config.getint('output') & config.OUT_TD:
td.export(data)
if config.getint('output') & config.OUT_BPC:
bpc.export(data, False)
if data['lastStarport'].get('commodities'):
if config.getint('output') & config.OUT_CSV:
bpc.export(data, True)
if config.getint('output') & config.OUT_TD:
td.export(data)
if config.getint('output') & config.OUT_BPC:
bpc.export(data, False)
if config.getint('output') & config.OUT_EDDN:
self.status['text'] = 'Sending data to EDDN...'
self.w.update_idletasks()
eddn.export(data)
self.status['text'] = strftime('Last updated at %H:%M:%S', localtime(querytime))
if data['lastStarport'].get('commodities') or data['lastStarport'].get('modules') or data['lastStarport'].get('ships'):
self.status['text'] = 'Sending data to EDDN...'
self.w.update_idletasks()
eddn.export(data)
self.status['text'] = strftime('Last updated at %H:%M:%S', localtime(querytime))
else:
self.status['text'] = "Station doesn't have anything!"
elif not data['lastStarport'].get('commodities'):
self.status['text'] = "Station doesn't have a market!"
else:
self.status['text'] = strftime('Last updated at %H:%M:%S', localtime(querytime))
except companion.VerificationRequired:
return prefs.AuthenticationDialog(self.w, self.verify)

View File

@ -180,7 +180,7 @@ class Session:
self.session = None
# Fixup anomalies in the recieved commodity data
# Fixup anomalies in the recieved commodity and shipyard data
def fixup(self, data):
commodities = data.get('lastStarport') and data['lastStarport'].get('commodities') or []
i=0
@ -225,6 +225,11 @@ class Session:
# Skip the commodity
commodities.pop(i)
if data['lastStarport'].get('ships'):
for ship in data['lastStarport']['ships'].get('shipyard_list', {}).values() + data['lastStarport']['ships'].get('unavailable_list', []):
if ship_map.get(ship['name']):
ship['name'] = ship_map[ship['name']]
return data
def dump(self, r):

59
eddn.py
View File

@ -9,9 +9,9 @@ from sys import platform
import time
from config import applongname, appversion, config
import outfitting
upload = 'http://eddn-gateway.elite-markets.net:8080/upload/'
schema = 'http://schemas.elite-markets.net/eddn/commodity/2'
bracketmap = { 1: 'Low',
2: 'Med',
@ -37,7 +37,7 @@ def export(data):
}
commodities = []
for commodity in data['lastStarport']['commodities']:
for commodity in data['lastStarport'].get('commodities', []):
commodities.append({
'name' : commodity['name'],
'buyPrice' : commodity['buyPrice'],
@ -50,13 +50,50 @@ def export(data):
if commodity['demandBracket']:
commodities[-1]['demandLevel'] = bracketmap[commodity['demandBracket']]
send({
'$schemaRef' : schema,
'header' : header,
'message' : {
'systemName' : data['lastSystem']['name'].strip(),
'stationName' : data['lastStarport']['name'].strip(),
'timestamp' : time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(querytime)),
'commodities' : commodities,
if data['lastStarport'].get('commodities'):
send({
'$schemaRef' : 'http://schemas.elite-markets.net/eddn/commodity/2',
'header' : header,
'message' : {
'systemName' : data['lastSystem']['name'].strip(),
'stationName' : data['lastStarport']['name'].strip(),
'timestamp' : time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(querytime)),
'commodities' : commodities,
}
})
})
modules = []
for v in data['lastStarport'].get('modules', {}).itervalues():
try:
module = outfitting.lookup(v)
if module:
modules.append(module)
except AssertionError as e:
if __debug__: print 'Outfitting: %s' % e # Silently skip unrecognized modules
except:
if __debug__: raise
if data['lastStarport'].get('modules'):
send({
'$schemaRef' : 'http://schemas.elite-markets.net/eddn/outfitting/1',
'header' : header,
'message' : {
'systemName' : data['lastSystem']['name'].strip(),
'stationName' : data['lastStarport']['name'].strip(),
'timestamp' : time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(querytime)),
'modules' : modules,
}
})
# Shipyard data is only guaranteed present if user has visited the shipyard. Only send if present.
if data['lastStarport'].get('ships'):
send({
'$schemaRef' : 'http://schemas.elite-markets.net/eddn/shipyard/1',
'header' : header,
'message' : {
'systemName' : data['lastSystem']['name'].strip(),
'stationName' : data['lastStarport']['name'].strip(),
'timestamp' : time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(querytime)),
'ships' : [ship['name'] for ship in data['lastStarport']['ships'].get('shipyard_list', {}).values() + data['lastStarport']['ships'].get('unavailable_list', [])],
}
})