mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-15 08:40:34 +03:00
try/except ModulesInfo.json load & fully document
This commit is contained in:
parent
fd0ce63341
commit
3fddd2bdf9
@ -427,6 +427,7 @@ Content of `state` (updated to the current journal entry):
|
||||
| `Rebuy` | `int` | Current ship's rebuy cost |
|
||||
| `Modules` | `dict` | Currently fitted modules |
|
||||
| `NavRoute` | `dict` | Last plotted multi-hop route |
|
||||
| `ModuleInfo` | `dict` | Last loaded ModulesInfo.json data |
|
||||
|
||||
##### Synthetic Events
|
||||
|
||||
@ -479,6 +480,11 @@ Examples of this are:
|
||||
}
|
||||
```
|
||||
|
||||
1. Every `ModuleInfo` event contains the full data as loaded from the
|
||||
`ModulesInfo.json` file. It's also available as `monitor.stat['ModuleInfo']`
|
||||
(noting that we used the singular form there to stay consistent with the
|
||||
Journal event name).
|
||||
|
||||
#### Player Dashboard
|
||||
|
||||
```python
|
||||
@ -515,6 +521,9 @@ New in version 5.0.0:
|
||||
`NavRoute` contains the `json.load()` of `NavRoute.json` as indicated by a journal
|
||||
`NavRoute` event.
|
||||
|
||||
`ModuleInfo` contains the `json.load()` of `ModulesInfo.json` as indicated by a
|
||||
Journal `ModuleInfo` event.
|
||||
|
||||
#### Getting Commander Data
|
||||
|
||||
```python
|
||||
|
10
monitor.py
10
monitor.py
@ -682,8 +682,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
|
||||
|
||||
elif event_type == 'ModuleInfo':
|
||||
with open(join(self.currentdir, 'ModulesInfo.json'), 'rb') as mf: # type: ignore
|
||||
entry = json.load(mf)
|
||||
self.state['ModuleInfo'] = entry
|
||||
try:
|
||||
entry = json.load(mf)
|
||||
|
||||
except json.JSONDecodeError:
|
||||
logger.exception('Failed decoding ModulesInfo.json', exc_info=True)
|
||||
|
||||
else:
|
||||
self.state['ModuleInfo'] = entry
|
||||
|
||||
elif event_type in ('CollectCargo', 'MarketBuy', 'BuyDrones', 'MiningRefined'):
|
||||
commodity = self.canonicalise(entry['Type'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user