mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-05 09:53:33 +03:00
Merge pull request #707 from EDCD/fix/671-no-modules
Catch where station modules and shipyard from CAPI aren't as expected.
This commit is contained in:
commit
7c9b8861fc
@ -530,11 +530,11 @@ class Session(object):
|
|||||||
"""Perform general CAPI /profile endpoint query."""
|
"""Perform general CAPI /profile endpoint query."""
|
||||||
return self.query(URL_QUERY)
|
return self.query(URL_QUERY)
|
||||||
|
|
||||||
def station(self) -> Union[CAPIData, None]:
|
def station(self) -> CAPIData:
|
||||||
"""Perform CAPI /profile endpoint query for station data."""
|
"""Perform CAPI /profile endpoint query for station data."""
|
||||||
data = self.query(URL_QUERY)
|
data = self.query(URL_QUERY)
|
||||||
if not data['commander'].get('docked'):
|
if not data['commander'].get('docked'):
|
||||||
return None
|
return data
|
||||||
|
|
||||||
services = data['lastStarport'].get('services', {})
|
services = data['lastStarport'].get('services', {})
|
||||||
|
|
||||||
|
@ -11,9 +11,9 @@ from collections import OrderedDict
|
|||||||
from os import SEEK_SET
|
from os import SEEK_SET
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from platform import system
|
from platform import system
|
||||||
from typing import TYPE_CHECKING, Any, AnyStr, Dict, Iterator, List, Mapping, MutableMapping, Optional
|
from typing import TYPE_CHECKING, Any, AnyStr, Dict, Iterator, List, Mapping, MutableMapping, Optional, Tuple
|
||||||
from typing import OrderedDict as OrderedDictT
|
from typing import OrderedDict as OrderedDictT
|
||||||
from typing import Sequence, TextIO, Tuple
|
from typing import Sequence, TextIO
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -262,6 +262,32 @@ Msg:\n{msg}''')
|
|||||||
|
|
||||||
this.commodities = commodities
|
this.commodities = commodities
|
||||||
|
|
||||||
|
def safe_modules_and_ships(self, data: Mapping[str, Any]) -> Tuple[Dict, Dict]:
|
||||||
|
modules: Dict[str, Any] = data['lastStarport'].get('modules')
|
||||||
|
if modules is None or not isinstance(modules, dict):
|
||||||
|
if modules is None:
|
||||||
|
logger.debug('modules was None. FC or Damaged Station?')
|
||||||
|
elif isinstance(modules, list):
|
||||||
|
if len(modules) == 0:
|
||||||
|
logger.debug('modules is empty list. Damaged Station?')
|
||||||
|
else:
|
||||||
|
logger.error(f'modules is non-empty list: {modules!r}')
|
||||||
|
else:
|
||||||
|
logger.error(f'modules was not None, a list, or a dict! type = {type(modules)}')
|
||||||
|
# Set a safe value
|
||||||
|
modules = {}
|
||||||
|
|
||||||
|
ships: Dict[str, Any] = data['lastStarport'].get('ships')
|
||||||
|
if ships is None or not isinstance(ships, dict):
|
||||||
|
if ships is None:
|
||||||
|
logger.debug('ships was None')
|
||||||
|
else:
|
||||||
|
logger.error(f'ships was neither None nor a Dict! Type = {type(ships)}')
|
||||||
|
# Set a safe value
|
||||||
|
ships = {'shipyard_list': {}, 'unavailable_list': []}
|
||||||
|
|
||||||
|
return modules, ships
|
||||||
|
|
||||||
def export_outfitting(self, data: Mapping[str, Any], is_beta: bool) -> None:
|
def export_outfitting(self, data: Mapping[str, Any], is_beta: bool) -> None:
|
||||||
"""
|
"""
|
||||||
export_outfitting updates EDDN with the current (lastStarport) station's outfitting options, if any.
|
export_outfitting updates EDDN with the current (lastStarport) station's outfitting options, if any.
|
||||||
@ -270,15 +296,7 @@ Msg:\n{msg}''')
|
|||||||
:param data: dict containing the outfitting data
|
:param data: dict containing the outfitting data
|
||||||
:param is_beta: whether or not we're currently in beta mode
|
:param is_beta: whether or not we're currently in beta mode
|
||||||
"""
|
"""
|
||||||
modules: Dict[str, Any] = data['lastStarport'].get('modules')
|
modules, ships = self.safe_modules_and_ships(data)
|
||||||
if modules is None:
|
|
||||||
logger.debug('modules was None')
|
|
||||||
modules = {}
|
|
||||||
|
|
||||||
ships: Dict[str, Any] = data['lastStarport'].get('ships')
|
|
||||||
if ships is None:
|
|
||||||
logger.debug('ships was None')
|
|
||||||
ships = {'shipyard_list': {}, 'unavailable_list': []}
|
|
||||||
|
|
||||||
# Horizons flag - will hit at least Int_PlanetApproachSuite other than at engineer bases ("Colony"),
|
# Horizons flag - will hit at least Int_PlanetApproachSuite other than at engineer bases ("Colony"),
|
||||||
# prison or rescue Megaships, or under Pirate Attack etc
|
# prison or rescue Megaships, or under Pirate Attack etc
|
||||||
@ -321,15 +339,7 @@ Msg:\n{msg}''')
|
|||||||
:param data: dict containing the shipyard data
|
:param data: dict containing the shipyard data
|
||||||
:param is_beta: whether or not we are in beta mode
|
:param is_beta: whether or not we are in beta mode
|
||||||
"""
|
"""
|
||||||
modules: Dict[str, Any] = data['lastStarport'].get('modules')
|
modules, ships = self.safe_modules_and_ships(data)
|
||||||
if modules is None:
|
|
||||||
logger.debug('modules was None')
|
|
||||||
modules = {}
|
|
||||||
|
|
||||||
ships: Dict[str, Any] = data['lastStarport'].get('ships')
|
|
||||||
if ships is None:
|
|
||||||
logger.debug('ships was None')
|
|
||||||
ships = {'shipyard_list': {}, 'unavailable_list': []}
|
|
||||||
|
|
||||||
horizons: bool = is_horizons(
|
horizons: bool = is_horizons(
|
||||||
data['lastStarport'].get('economies', {}),
|
data['lastStarport'].get('economies', {}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user