From 6ffcfc74a18e2531df42f0cf5205764be3e00faa Mon Sep 17 00:00:00 2001
From: Jonathan Harris <jonathan@marginal.org.uk>
Date: Thu, 24 Aug 2017 19:21:53 +0100
Subject: [PATCH] Send 2.4-style mod info to EDShipyard and Coriolis

---
 companion.py  | 29 ++++++++++++++++++-----------
 coriolis.py   |  2 +-
 edshipyard.py |  2 +-
 loadout.py    |  2 +-
 4 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/companion.py b/companion.py
index a7def480..10913af7 100644
--- a/companion.py
+++ b/companion.py
@@ -381,20 +381,27 @@ def ship(data):
     # subset of "ship" that's not noisy
     description = {}
     for props in [
-            ('cargo', 'capacity'),
-            ('free',),
-            ('fuel', 'main', 'capacity'),
-            ('fuel', 'reserve', 'capacity'),
-            ('id',),
-            ('name',),
-            ('value', 'hull'),
-            ('value', 'modules'),
-            ('value', 'unloaned'),
+        ('cargo', 'capacity'),
+        ('free',),
+        ('fuel', 'main', 'capacity'),
+        ('fuel', 'reserve', 'capacity'),
+        ('id',),
+        ('launchBays',),
+        ('name',),
+        ('shipID',),
+        ('shipName',),
+        ('value', 'hull'),
+        ('value', 'modules'),
+        ('value', 'unloaned'),
     ]: addleaf(data['ship'], description, props)
 
     description['modules'] = {}
     for slot in data['ship'].get('modules', {}):
-        for prop in ['free', 'id', 'modifiers', 'name', 'on', 'priority', 'recipeLevel', 'recipeName', 'recipeValue', 'unloaned', 'value']:
-            addleaf(data['ship']['modules'], description['modules'], (slot, 'module', prop))
+        for prop in data['ship']['modules'][slot]:
+            if prop == 'module':
+                for prop2 in ['free', 'id', 'name', 'on', 'priority', 'value', 'unloaned']:
+                    addleaf(data['ship']['modules'], description['modules'], (slot, prop, prop2))
+            else:
+                addleaf(data['ship']['modules'], description['modules'], (slot, prop))
 
     return description
diff --git a/coriolis.py b/coriolis.py
index 240e595c..46b78a93 100755
--- a/coriolis.py
+++ b/coriolis.py
@@ -18,7 +18,7 @@ import companion
 # Return a URL for the current ship
 def url(data, is_beta):
 
-    string = json.dumps(companion.ship(data), ensure_ascii=False, sort_keys=True, separators=(',', ':'))	# most compact representation
+    string = json.dumps(companion.ship(data), ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8')	# most compact representation
 
     out = StringIO.StringIO()
     with gzip.GzipFile(fileobj=out, mode='w') as f:
diff --git a/edshipyard.py b/edshipyard.py
index 511405a6..03a74ec8 100644
--- a/edshipyard.py
+++ b/edshipyard.py
@@ -154,7 +154,7 @@ def export(data, filename=None):
 # Return a URL for the current ship
 def url(data, is_beta):
 
-    string = json.dumps(companion.ship(data), ensure_ascii=False, sort_keys=True, separators=(',', ':'))	# most compact representation
+    string = json.dumps(companion.ship(data), ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8')	# most compact representation
 
     out = StringIO.StringIO()
     with gzip.GzipFile(fileobj=out, mode='w') as f:
diff --git a/loadout.py b/loadout.py
index 688af85d..872f6f1f 100644
--- a/loadout.py
+++ b/loadout.py
@@ -11,7 +11,7 @@ import companion
 # Export ship loadout in Companion API json format
 def export(data, filename=None):
 
-    string = json.dumps(companion.ship(data), ensure_ascii=False, indent=2, sort_keys=True, separators=(',', ': '))	# pretty print
+    string = json.dumps(companion.ship(data), ensure_ascii=False, indent=2, sort_keys=True, separators=(',', ': ')).encode('utf-8')	# pretty print
 
     if filename:
         with open(filename, 'wt') as h: