mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-15 08:40:34 +03:00
Odyssey Suits: Store available data from CAPI.
I've gone with 'None' for when there's no data, rather than {}. That makes for simpler checks on if there is data (a dict.get('foo') only checks for that, not the dict structure otherwise). If no 'suit' in the data we assume no Odyssey, but otherwise plough on with dict.get() statements as they'll default to None if it's not present. *Users* of this monitor.state[] extra data get to choose what to do if some data is present but not other.
This commit is contained in:
parent
a70da4a522
commit
2246278286
23
companion.py
23
companion.py
@ -589,6 +589,10 @@ class Session(object):
|
||||
# logger.trace('timestamp not in data, adding from response headers')
|
||||
data['timestamp'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', parsedate(r.headers['Date'])) # type: ignore
|
||||
|
||||
# Update Odyssey Suit data
|
||||
if endpoint == URL_QUERY:
|
||||
self.suit_update(data)
|
||||
|
||||
return data
|
||||
|
||||
def profile(self) -> CAPIData:
|
||||
@ -632,6 +636,25 @@ class Session(object):
|
||||
|
||||
return data
|
||||
|
||||
def suit_update(self, data: CAPIData) -> None:
|
||||
"""
|
||||
Update monitor.state suit data.
|
||||
|
||||
:param data: CAPI data to extra suit data from.
|
||||
"""
|
||||
if (current_suit := data.get('suit')) is None:
|
||||
# Probably no Odyssey on the account, so point attempting more.
|
||||
return
|
||||
|
||||
monitor.state['SuitCurrent'] = current_suit
|
||||
monitor.state['Suits'] = data.get('suits')
|
||||
|
||||
if (suit_loadouts := data.get('loadouts')) is None:
|
||||
logger.warning('CAPI data had "suit" but no (suit) "loadouts"')
|
||||
|
||||
monitor.state['SuitLoadoutCurrent'] = data.get('loadout')
|
||||
monitor.state['SuitLoadouts'] = suit_loadouts
|
||||
|
||||
def close(self) -> None:
|
||||
"""Close CAPI authorization session."""
|
||||
self.state = Session.STATE_INIT
|
||||
|
@ -23,6 +23,11 @@ companion_category_map = {
|
||||
'NonMarketable': False, # Don't appear in the in-game market so don't report
|
||||
}
|
||||
|
||||
# Map suit symbol names to English localised names
|
||||
companion_suit_type_map = {
|
||||
'TacticalSuit_Class1': 'Dominator Suit',
|
||||
}
|
||||
|
||||
# Map Coriolis's names to names displayed in the in-game shipyard.
|
||||
coriolis_ship_map = {
|
||||
'Cobra Mk III': 'Cobra MkIII',
|
||||
|
72
monitor.py
72
monitor.py
@ -114,42 +114,46 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
|
||||
# Cmdr state shared with EDSM and plugins
|
||||
# If you change anything here update PLUGINS.md documentation!
|
||||
self.state: Dict = {
|
||||
'Captain': None, # On a crew
|
||||
'Cargo': defaultdict(int),
|
||||
'Credits': None,
|
||||
'FID': None, # Frontier Cmdr ID
|
||||
'Horizons': None, # Does this user have Horizons?
|
||||
'Loan': None,
|
||||
'Raw': defaultdict(int),
|
||||
'Manufactured': defaultdict(int),
|
||||
'Encoded': defaultdict(int),
|
||||
'Engineers': {},
|
||||
'Rank': {},
|
||||
'Reputation': {},
|
||||
'Statistics': {},
|
||||
'Role': None, # Crew role - None, Idle, FireCon, FighterCon
|
||||
'Friends': set(), # Online friends
|
||||
'ShipID': None,
|
||||
'ShipIdent': None,
|
||||
'ShipName': None,
|
||||
'ShipType': None,
|
||||
'HullValue': None,
|
||||
'ModulesValue': None,
|
||||
'Rebuy': None,
|
||||
'Modules': None,
|
||||
'CargoJSON': None, # The raw data from the last time cargo.json was read
|
||||
'Route': None, # Last plotted route from Route.json file
|
||||
'OnFoot': False, # Whether we think you're on-foot
|
||||
'Component': defaultdict(int), # Odyssey Components in Ship Locker
|
||||
'Item': defaultdict(int), # Odyssey Items in Ship Locker
|
||||
'Consumable': defaultdict(int), # Odyssey Consumables in Ship Locker
|
||||
'Data': defaultdict(int), # Odyssey Data in Ship Locker
|
||||
'Captain': None, # On a crew
|
||||
'Cargo': defaultdict(int),
|
||||
'Credits': None,
|
||||
'FID': None, # Frontier Cmdr ID
|
||||
'Horizons': None, # Does this user have Horizons?
|
||||
'Loan': None,
|
||||
'Raw': defaultdict(int),
|
||||
'Manufactured': defaultdict(int),
|
||||
'Encoded': defaultdict(int),
|
||||
'Engineers': {},
|
||||
'Rank': {},
|
||||
'Reputation': {},
|
||||
'Statistics': {},
|
||||
'Role': None, # Crew role - None, Idle, FireCon, FighterCon
|
||||
'Friends': set(), # Online friends
|
||||
'ShipID': None,
|
||||
'ShipIdent': None,
|
||||
'ShipName': None,
|
||||
'ShipType': None,
|
||||
'HullValue': None,
|
||||
'ModulesValue': None,
|
||||
'Rebuy': None,
|
||||
'Modules': None,
|
||||
'CargoJSON': None, # The raw data from the last time cargo.json was read
|
||||
'Route': None, # Last plotted route from Route.json file
|
||||
'OnFoot': False, # Whether we think you're on-foot
|
||||
'Component': defaultdict(int), # Odyssey Components in Ship Locker
|
||||
'Item': defaultdict(int), # Odyssey Items in Ship Locker
|
||||
'Consumable': defaultdict(int), # Odyssey Consumables in Ship Locker
|
||||
'Data': defaultdict(int), # Odyssey Data in Ship Locker
|
||||
'BackPack': { # Odyssey BackPack contents
|
||||
'Component': defaultdict(int), # BackPack Components
|
||||
'Consumable': defaultdict(int), # BackPack Consumables
|
||||
'Item': defaultdict(int), # BackPack Items
|
||||
'Data': defaultdict(int), # Backpack Data
|
||||
'Component': defaultdict(int), # BackPack Components
|
||||
'Consumable': defaultdict(int), # BackPack Consumables
|
||||
'Item': defaultdict(int), # BackPack Items
|
||||
'Data': defaultdict(int), # Backpack Data
|
||||
},
|
||||
'SuitCurrent': None,
|
||||
'Suits': None,
|
||||
'SuitLoadoutCurrent': None,
|
||||
'SuitLoadouts': None,
|
||||
}
|
||||
|
||||
def start(self, root: 'tkinter.Tk') -> bool: # noqa: CCR001
|
||||
|
Loading…
x
Reference in New Issue
Block a user