mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-14 08:17:13 +03:00
Only care about lastStarport if docked
This commit is contained in:
parent
0e93b39f4e
commit
1767df031a
14
EDMC.py
14
EDMC.py
@ -129,7 +129,8 @@ try:
|
||||
if not data.get('commander') or not data['commander'].get('name','').strip():
|
||||
sys.stderr.write('Who are you?!\n')
|
||||
sys.exit(EXIT_SERVER)
|
||||
elif not data.get('lastSystem') or not data['lastSystem'].get('name','').strip() or not data.get('lastStarport') or not data['lastStarport'].get('name','').strip():
|
||||
elif (not data.get('lastSystem', {}).get('name') or
|
||||
(data['commander'].get('docked') and not data.get('lastStarport', {}).get('name'))): # Only care if docked
|
||||
sys.stderr.write('Where are you?!\n') # Shouldn't happen
|
||||
sys.exit(EXIT_SERVER)
|
||||
elif not data.get('ship') or not data['ship'].get('modules') or not data['ship'].get('name','').strip():
|
||||
@ -161,14 +162,17 @@ try:
|
||||
stats.export_status(data, args.t)
|
||||
|
||||
if data['commander'].get('docked'):
|
||||
print '%s,%s' % (data['lastSystem']['name'], data['lastStarport']['name'])
|
||||
print '%s,%s' % (data.get('lastSystem', {}).get('name', 'Unknown'), data.get('lastStarport', {}).get('name', 'Unknown'))
|
||||
else:
|
||||
print data['lastSystem']['name']
|
||||
print data.get('lastSystem', {}).get('name', 'Unknown')
|
||||
|
||||
if (args.m or args.o or args.s or args.n or args.j):
|
||||
if not data['commander'].get('docked'):
|
||||
sys.stderr.write("You're not docked at a station!\n")
|
||||
sys.exit(EXIT_SUCCESS)
|
||||
elif not data.get('lastStarport', {}).get('name'):
|
||||
sys.stderr.write("Unknown station!\n")
|
||||
sys.exit(EXIT_LAGGING)
|
||||
elif not (data['lastStarport'].get('commodities') or data['lastStarport'].get('modules')): # Ignore possibly missing shipyard info
|
||||
sys.stderr.write("Station doesn't have anything!\n")
|
||||
sys.exit(EXIT_SUCCESS)
|
||||
@ -202,8 +206,8 @@ try:
|
||||
sleep(SERVER_RETRY)
|
||||
data2 = session.station()
|
||||
if (data2['commander'].get('docked') and # might have undocked while we were waiting for retry in which case station data is unreliable
|
||||
data2['lastSystem']['name'] == monitor.system and
|
||||
data2['lastStarport']['name'] == monitor.station):
|
||||
data2.get('lastSystem', {}).get('name') == monitor.system and
|
||||
data2.get('lastStarport', {}).get('name') == monitor.station):
|
||||
data = data2
|
||||
|
||||
if args.s:
|
||||
|
@ -432,11 +432,12 @@ class AppWindow:
|
||||
config.set('querytime', querytime)
|
||||
|
||||
# Validation
|
||||
if not data.get('commander') or not data['commander'].get('name','').strip():
|
||||
if not data.get('commander', {}).get('name'):
|
||||
self.status['text'] = _("Who are you?!") # Shouldn't happen
|
||||
elif not data.get('lastSystem') or not data['lastSystem'].get('name','').strip() or not data.get('lastStarport') or not data['lastStarport'].get('name','').strip():
|
||||
elif (not data.get('lastSystem', {}).get('name') or
|
||||
(data['commander'].get('docked') and not data.get('lastStarport', {}).get('name'))): # Only care if docked
|
||||
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():
|
||||
elif not data.get('ship', {}).get('name') or not data.get('ship', {}).get('modules'):
|
||||
self.status['text'] = _("What are you flying?!") # Shouldn't happen
|
||||
elif monitor.cmdr and data['commander']['name'] != monitor.cmdr:
|
||||
raise companion.CmdrError() # Companion API return doesn't match Journal
|
||||
@ -556,12 +557,12 @@ class AppWindow:
|
||||
try:
|
||||
data = self.session.station()
|
||||
if __debug__:
|
||||
print 'Retry for shipyard - ' + (data['commander'].get('docked') and (data['lastStarport'].get('ships') and 'Success' or 'Failure') or 'Undocked!')
|
||||
print 'Retry for shipyard - ' + (data['commander'].get('docked') and (data.get('lastStarport', {}).get('ships') and 'Success' or 'Failure') or 'Undocked!')
|
||||
if not data['commander'].get('docked'):
|
||||
pass # might have undocked while we were waiting for retry in which case station data is unreliable
|
||||
elif (data['lastStarport'].get('ships') and
|
||||
data['lastSystem']['name'] == monitor.system and
|
||||
data['lastStarport']['name'] == monitor.station):
|
||||
elif (data.get('lastSystem', {}).get('name') == monitor.system and
|
||||
data.get('lastStarport', {}).get('name') == monitor.station and
|
||||
data.get('lastStarport', {}).get('ships')):
|
||||
self.eddn.export_shipyard(data, monitor.is_beta)
|
||||
elif tries > 1: # bogus data - retry
|
||||
self.w.after(int(SERVER_RETRY * 1000), lambda:self.retry_for_shipyard(tries-1))
|
||||
@ -732,11 +733,12 @@ class AppWindow:
|
||||
self.status['text'] = str(e)
|
||||
return
|
||||
|
||||
if not data.get('commander') or not data['commander'].get('name','').strip():
|
||||
if not data.get('commander', {}).get('name'):
|
||||
self.status['text'] = _("Who are you?!") # Shouldn't happen
|
||||
elif not data.get('lastSystem') or not data['lastSystem'].get('name','').strip() or not data.get('lastStarport') or not data['lastStarport'].get('name','').strip():
|
||||
elif (not data.get('lastSystem', {}).get('name') or
|
||||
(data['commander'].get('docked') and not data.get('lastStarport', {}).get('name'))): # Only care if docked
|
||||
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():
|
||||
elif not data.get('ship', {}).get('name') or not data.get('ship', {}).get('modules'):
|
||||
self.status['text'] = _("What are you flying?!") # Shouldn't happen
|
||||
elif (monitor.state['ShipID'] is not None and data['ship']['id'] != monitor.state['ShipID']) or (monitor.state['ShipType'] and data['ship']['name'].lower() != monitor.state['ShipType']):
|
||||
self.status['text'] = _('Error: Frontier server is lagging') # Raised when Companion API server is returning old data, e.g. when the servers are too busy
|
||||
@ -788,7 +790,7 @@ class AppWindow:
|
||||
defaultextension = platform=='darwin' and '.json' or '',
|
||||
filetypes = [('JSON', '.json'), ('All Files', '*')],
|
||||
initialdir = config.get('outdir'),
|
||||
initialfile = '%s%s.%s.json' % (data['lastSystem'].get('name', 'Unknown'), data['commander'].get('docked') and '.'+data['lastStarport'].get('name', 'Unknown') or '', strftime('%Y-%m-%dT%H.%M.%S', localtime())))
|
||||
initialfile = '%s%s.%s.json' % (data.get('lastSystem', {}).get('name', 'Unknown'), data['commander'].get('docked') and '.'+data.get('lastStarport', {}).get('name', 'Unknown') or '', strftime('%Y-%m-%dT%H.%M.%S', localtime())))
|
||||
if f:
|
||||
with open(f, 'wt') as h:
|
||||
h.write(json.dumps(data, ensure_ascii=False, indent=2, sort_keys=True, separators=(',', ': ')).encode('utf-8'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user