mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-04 01:21:03 +03:00
CAPI: Remove unuses Session.query/profile()
* Session.profile() was unused (used to be called from stats.py, but that uses cached data now). * Session.query() was unused, other than by itself. Normal calls will currently be via companion.Session.station(). Future CAPI queries like `/fleetcarrier` might add their own companion.Session function. * And in doing so get --capi-pretend-down working again. * Small tweak to EDMarketConnector to not throw extra exception if there was a CAPI query exception.
This commit is contained in:
parent
60379892ee
commit
796bb1f863
@ -1106,6 +1106,8 @@ class AppWindow(object):
|
|||||||
self.suit['text'] = f'{suitname} ({loadout_name})'
|
self.suit['text'] = f'{suitname} ({loadout_name})'
|
||||||
|
|
||||||
self.suit_show_if_set()
|
self.suit_show_if_set()
|
||||||
|
# Update Odyssey Suit data
|
||||||
|
companion.session.suit_update(capi_response.capi_data)
|
||||||
|
|
||||||
if capi_response.capi_data['commander'].get('credits') is not None:
|
if capi_response.capi_data['commander'].get('credits') is not None:
|
||||||
monitor.state['Credits'] = capi_response.capi_data['commander']['credits']
|
monitor.state['Credits'] = capi_response.capi_data['commander']['credits']
|
||||||
@ -1174,9 +1176,6 @@ class AppWindow(object):
|
|||||||
if capi_response.play_sound and play_bad:
|
if capi_response.play_sound and play_bad:
|
||||||
hotkeymgr.play_bad()
|
hotkeymgr.play_bad()
|
||||||
|
|
||||||
# Update Odyssey Suit data
|
|
||||||
companion.session.suit_update(capi_response.capi_data)
|
|
||||||
|
|
||||||
logger.trace_if('capi.worker', 'Updating suit and cooldown...')
|
logger.trace_if('capi.worker', 'Updating suit and cooldown...')
|
||||||
self.update_suit_text()
|
self.update_suit_text()
|
||||||
self.suit_show_if_set()
|
self.suit_show_if_set()
|
||||||
|
67
companion.py
67
companion.py
@ -747,6 +747,9 @@ class Session(object):
|
|||||||
capi_data: CAPIData
|
capi_data: CAPIData
|
||||||
try:
|
try:
|
||||||
logger.trace_if('capi.worker', 'Sending HTTP request...')
|
logger.trace_if('capi.worker', 'Sending HTTP request...')
|
||||||
|
if conf_module.capi_pretend_down:
|
||||||
|
raise ServerConnectionError(f'Pretending CAPI down: {capi_endpoint}')
|
||||||
|
|
||||||
r = self.requests_session.get(self.server + capi_endpoint, timeout=timeout) # type: ignore
|
r = self.requests_session.get(self.server + capi_endpoint, timeout=timeout) # type: ignore
|
||||||
logger.trace_if('capi.worker', '... got result...')
|
logger.trace_if('capi.worker', '... got result...')
|
||||||
r.raise_for_status() # Typically 403 "Forbidden" on token expiry
|
r.raise_for_status() # Typically 403 "Forbidden" on token expiry
|
||||||
@ -933,70 +936,6 @@ class Session(object):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def query(
|
|
||||||
self, endpoint: str, query_time: int,
|
|
||||||
tk_response_event: Optional[str] = None,
|
|
||||||
play_sound: bool = False, auto_update: bool = False
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Perform a query against the specified CAPI endpoint.
|
|
||||||
|
|
||||||
:param endpoint: The CAPI endpoint to query.
|
|
||||||
:param tk_response_event: Name of tk event to generate when response queued.
|
|
||||||
:param query_time: When this query was initiated.
|
|
||||||
:param play_sound: Whether the app should play a sound on error.
|
|
||||||
:param auto_update: Whether this request was triggered automatically.
|
|
||||||
"""
|
|
||||||
logger.trace_if('capi.query', f'Performing query for endpoint "{endpoint}"')
|
|
||||||
if self.state == Session.STATE_INIT:
|
|
||||||
if self.login():
|
|
||||||
self.query(
|
|
||||||
endpoint, query_time, tk_response_event=tk_response_event, play_sound=play_sound,
|
|
||||||
auto_update=auto_update
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
elif self.state == Session.STATE_AUTH:
|
|
||||||
logger.error('cannot make a query when unauthorized')
|
|
||||||
raise CredentialsError('cannot make a query when unauthorized')
|
|
||||||
|
|
||||||
logger.trace_if('capi.query', 'Trying...')
|
|
||||||
if conf_module.capi_pretend_down:
|
|
||||||
raise ServerConnectionError(f'Pretending CAPI down: {endpoint}')
|
|
||||||
|
|
||||||
self.capi_request_queue.put(
|
|
||||||
EDMCCAPIRequest(
|
|
||||||
endpoint=endpoint,
|
|
||||||
tk_response_event=tk_response_event,
|
|
||||||
query_time=query_time,
|
|
||||||
play_sound=play_sound,
|
|
||||||
auto_update=auto_update
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def profile(
|
|
||||||
self,
|
|
||||||
query_time: int = 0,
|
|
||||||
tk_response_event: Optional[str] = None,
|
|
||||||
play_sound: bool = False, auto_update: bool = False
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Perform general CAPI /profile endpoint query.
|
|
||||||
|
|
||||||
:param query_time: When this query was initiated.
|
|
||||||
:param tk_response_event: Name of tk event to generate when response queued.
|
|
||||||
:param play_sound: Whether the app should play a sound on error.
|
|
||||||
:param auto_update: Whether this request was triggered automatically.
|
|
||||||
"""
|
|
||||||
if query_time == 0:
|
|
||||||
query_time = int(time.time())
|
|
||||||
|
|
||||||
self.query(
|
|
||||||
self.FRONTIER_CAPI_PATH_PROFILE, query_time=query_time,
|
|
||||||
tk_response_event=tk_response_event,
|
|
||||||
play_sound=play_sound, auto_update=auto_update
|
|
||||||
)
|
|
||||||
|
|
||||||
def station(
|
def station(
|
||||||
self, query_time: int, tk_response_event: Optional[str] = None,
|
self, query_time: int, tk_response_event: Optional[str] = None,
|
||||||
play_sound: bool = False, auto_update: bool = False
|
play_sound: bool = False, auto_update: bool = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user