diff --git a/coriolis.py b/coriolis.py index 33cf1e99..e9d7033d 100755 --- a/coriolis.py +++ b/coriolis.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # # build ship and module databases from https://github.com/EDCD/coriolis-data/ # @@ -6,7 +6,7 @@ import csv import base64 from collections import OrderedDict -import cPickle +import pickle import json import subprocess import sys @@ -39,15 +39,15 @@ if __name__ == "__main__": } # Symbolic name from in-game name - reverse_ship_map = {v: k for k, v in companion.ship_map.items()} + reverse_ship_map = {v: k for k, v in list(companion.ship_map.items())} - bulkheads = outfitting.armour_map.keys() + bulkheads = list(outfitting.armour_map.keys()) ships = {} modules = {} # Ship and armour masses - for m in data['Ships'].values(): + for m in list(data['Ships'].values()): name = coriolis_ship_map.get(m['properties']['name'], str(m['properties']['name'])) assert name in reverse_ship_map, name ships[name] = { 'hullMass' : m['properties']['hullMass'] } @@ -55,11 +55,11 @@ if __name__ == "__main__": modules['_'.join([reverse_ship_map[name], 'armour', bulkheads[i]])] = { 'mass': m['bulkheads'][i]['mass'] } ships = OrderedDict([(k,ships[k]) for k in sorted(ships)]) # sort for easier diffing - cPickle.dump(ships, open('ships.p', 'wb')) + pickle.dump(ships, open('ships.p', 'wb')) # Module masses - for cat in data['Modules'].values(): - for grp, mlist in cat.items(): + for cat in list(data['Modules'].values()): + for grp, mlist in list(cat.items()): for m in mlist: assert 'symbol' in m, m key = str(m['symbol'].lower()) @@ -91,7 +91,7 @@ if __name__ == "__main__": add(modules, 'hpt_multicannon_fixed_medium_advanced', { 'mass': 4 }) modules = OrderedDict([(k,modules[k]) for k in sorted(modules)]) # sort for easier diffing - cPickle.dump(modules, open('modules.p', 'wb')) + pickle.dump(modules, open('modules.p', 'wb')) # Check data is present for all modules with open('outfitting.csv') as csvfile: @@ -100,5 +100,5 @@ if __name__ == "__main__": try: module = outfitting.lookup({ 'id': row['id'], 'name': row['symbol'] }, companion.ship_map) except: - print row['symbol'] + print(row['symbol']) print_exc() diff --git a/outfitting.py b/outfitting.py index ebd675a6..cf7e27dc 100644 --- a/outfitting.py +++ b/outfitting.py @@ -1,5 +1,5 @@ from collections import OrderedDict -import cPickle +import pickle from os.path import join import time @@ -350,7 +350,7 @@ def lookup(module, ship_map, entitled=False): # Lazily populate if not moduledata: - moduledata.update(cPickle.load(open(join(config.respath, 'modules.p'), 'rb'))) + moduledata.update(pickle.load(open(join(config.respath, 'modules.p'), 'rb'))) # if not module.get('category'): raise AssertionError('%s: Missing category' % module['id']) # only present post 1.3, and not present in ship loadout if not module.get('name'): raise AssertionError('%s: Missing name' % module['id']) @@ -464,7 +464,12 @@ def lookup(module, ship_map, entitled=False): (new['class'], new['rating']) = (str(name[2][4:]), 'A') elif len(name) < 4 and name[1] in ['guardianfsdbooster']: # Hack! No class. (new['class'], new['rating']) = (str(name[2][4:]), 'H') + elif len(name) < 4 and name[0] == 'dronecontrol' and name[1] == 'resourcesiphon': + # 128066402,Int_DroneControl_ResourceSiphon,internal,Limpet Control,,,,1,I, + (new['class'], new['rating']) = (1, 'I') else: + if len(name) < 3: + raise AssertionError('%s: length < 3]' % (name)) if not name[2].startswith('size') or not name[3].startswith('class'): raise AssertionError('%s: Unknown class/rating "%s/%s"' % (module['id'], name[2], name[3])) new['class'] = str(name[2][4:]) new['rating'] = (name[1]=='buggybay' and planet_rating_map or @@ -490,7 +495,7 @@ def lookup(module, ship_map, entitled=False): if __debug__: m = moduledata.get(key, {}) if not m: - print 'No data for module %s' % key + print('No data for module %s' % key) elif new['name'] == 'Frame Shift Drive': assert 'mass' in m and 'optmass' in m and 'maxfuel' in m and 'fuelmul' in m and 'fuelpower' in m, m else: @@ -518,13 +523,13 @@ def export(data, filename): h = open(filename, 'wt') h.write(header) - for v in data['lastStarport'].get('modules', {}).itervalues(): + for v in list(data['lastStarport'].get('modules', {}).values()): try: m = lookup(v, companion.ship_map) if m: h.write('%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n' % (rowheader, m['category'], m['name'], m.get('mount',''), m.get('guidance',''), m.get('ship',''), m['class'], m['rating'], m['id'], data['timestamp'])) except AssertionError as e: - if __debug__: print 'Outfitting: %s' % e # Silently skip unrecognized modules + if __debug__: print('Outfitting: %s' % e) # Silently skip unrecognized modules except: if __debug__: raise h.close()