mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-07 10:53:26 +03:00
companion: Improve station() checks and documentation
* Expand on the docstring to point out extra queries might be made. * Add checks for lastStarport and then name within that being properly present and set.
This commit is contained in:
parent
74a3bea619
commit
e4f7c998cd
36
companion.py
36
companion.py
@ -604,7 +604,17 @@ class Session(object):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def station(self) -> CAPIData: # noqa: CCR001
|
def station(self) -> CAPIData: # noqa: CCR001
|
||||||
"""Perform CAPI /profile endpoint query for station data."""
|
"""
|
||||||
|
Perform CAPI quer(y|ies) for station data.
|
||||||
|
|
||||||
|
A /profile query is performed to check that we are docked (or on foot)
|
||||||
|
and the station name and marketid match the prior Docked event.
|
||||||
|
If they do match, and the services list says they're present, also
|
||||||
|
retrieve CAPI market and/or shipyard/outfitting data and merge into
|
||||||
|
the /profile data.
|
||||||
|
|
||||||
|
:return: Possibly augmented CAPI data.
|
||||||
|
"""
|
||||||
data = self.query(URL_QUERY)
|
data = self.query(URL_QUERY)
|
||||||
if 'commander' not in data:
|
if 'commander' not in data:
|
||||||
logger.error('No commander in returned data')
|
logger.error('No commander in returned data')
|
||||||
@ -613,17 +623,33 @@ class Session(object):
|
|||||||
if not data['commander'].get('docked') and not monitor.state['OnFoot']:
|
if not data['commander'].get('docked') and not monitor.state['OnFoot']:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
services = data['lastStarport'].get('services', {})
|
# Sanity checks in case data isn't as we expect, and maybe 'docked' flag
|
||||||
|
# is also lagging.
|
||||||
|
if (last_starport := data.get('lastStarport')) is None:
|
||||||
|
logger.error("No lastStarport in data!")
|
||||||
|
return data
|
||||||
|
|
||||||
|
if ((last_starport_name := last_starport.get('name')) is None
|
||||||
|
or last_starport_name == ''):
|
||||||
|
# This could well be valid if you've been out exploring for a long
|
||||||
|
# time.
|
||||||
|
logger.warning("No lastStarport name!")
|
||||||
|
return data
|
||||||
|
|
||||||
|
services = last_starport.get('services', {})
|
||||||
if not isinstance(services, dict):
|
if not isinstance(services, dict):
|
||||||
# This happens if you're in-ship in-space and force an Update
|
# Odyssey Alpha Phase 3 4.0.0.20 has been observed having
|
||||||
|
# this be an empty list when you've jumped to another system
|
||||||
|
# and not yet docked. As opposed to no services key at all
|
||||||
|
# or an empty dict.
|
||||||
logger.error(f'services is "{type(services)}", not dict !')
|
logger.error(f'services is "{type(services)}", not dict !')
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self.dump_capi_data(data)
|
self.dump_capi_data(data)
|
||||||
|
|
||||||
|
# Set an empty dict so as to not have to retest below.
|
||||||
services = {}
|
services = {}
|
||||||
|
|
||||||
last_starport_name = data['lastStarport']['name']
|
last_starport_id = int(last_starport.get('id'))
|
||||||
last_starport_id = int(data['lastStarport']['id'])
|
|
||||||
|
|
||||||
if services.get('commodities'):
|
if services.get('commodities'):
|
||||||
marketdata = self.query(URL_MARKET)
|
marketdata = self.query(URL_MARKET)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user