From 8c3b0b8de3ee1a455191156c3368910505f7810e Mon Sep 17 00:00:00 2001
From: Jonathan Harris <jonathan@marginal.org.uk>
Date: Wed, 31 Oct 2018 19:11:55 +0000
Subject: [PATCH] Handle new Cargo event variant in 3.3

---
 monitor.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/monitor.py b/monitor.py
index 923f8c91..80e1c1ce 100644
--- a/monitor.py
+++ b/monitor.py
@@ -491,6 +491,9 @@ class EDLogs(FileSystemEventHandler):
 
             elif entry['event'] == 'Cargo':
                 self.state['Cargo'] = defaultdict(int)
+                if 'Inventory' not in entry:	# From 3.3 full Cargo event (after the first one) is written to a separate file
+                    with open(join(self.currentdir, 'Cargo.json'), 'rb') as h:
+                        entry = json.load(h, object_pairs_hook=OrderedDict)	# Preserve property order because why not?
                 self.state['Cargo'].update({ self.canonicalise(x['Name']): x['Count'] for x in entry['Inventory'] })
             elif entry['event'] in ['CollectCargo', 'MarketBuy', 'BuyDrones', 'MiningRefined']:
                 commodity = self.canonicalise(entry['Type'])