From 27d7265c868562a70c805dcc19855d40267cb312 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 20 Sep 2019 14:47:12 +0100 Subject: [PATCH] Cleanup of EDMC.py and related code. All flags tested. Mostly the usual file-mode versus .encode('utf-8') tweaks, but also one list() needed around a .values(). --- EDMC.py | 2 +- edshipyard.py | 2 +- loadout.py | 2 +- shipyard.py | 2 +- stats.py | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/EDMC.py b/EDMC.py index 5c319b95..91f8e589 100755 --- a/EDMC.py +++ b/EDMC.py @@ -147,7 +147,7 @@ try: # stuff we can do when not docked if args.d: - with open(args.d, 'wt') as h: + with open(args.d, 'wb') as h: h.write(json.dumps(data, ensure_ascii=False, indent=2, sort_keys=True, separators=(',', ': ')).encode('utf-8')) if args.a: loadout.export(data, args.a) diff --git a/edshipyard.py b/edshipyard.py index f8de96fe..4f0b5563 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -117,7 +117,7 @@ def export(data, filename=None): # Construct description ship = ship_map.get(data['ship']['name'].lower(), data['ship']['name']) - string = '[%s]\n' % (data['ship'].get('shipName') and ', '.join([ship, data['ship']['shipName'].encode('utf-8')]) or ship) + string = '[%s]\n' % (data['ship'].get('shipName') and ', '.join([ship, data['ship']['shipName']]) or ship) for slot in ['H', 'L', 'M', 'S', 'U', None, 'BH', 'RB', 'TM', 'FH', 'EC', 'PC', 'SS', 'FS', None, 'MC', None, '9', '8', '7', '6', '5', '4', '3', '2', '1']: if not slot: string += '\n' diff --git a/loadout.py b/loadout.py index 1f9995ad..6814c18f 100644 --- a/loadout.py +++ b/loadout.py @@ -12,7 +12,7 @@ import companion def export(data, filename=None): - string = json.dumps(companion.ship(data), ensure_ascii=False, indent=2, sort_keys=True, separators=(',', ': ')).encode('utf-8') # pretty print + string = json.dumps(companion.ship(data), ensure_ascii=False, indent=2, sort_keys=True, separators=(',', ': ')) # pretty print if filename: with open(filename, 'wt') as h: diff --git a/shipyard.py b/shipyard.py index 108a9b89..fe31d33e 100644 --- a/shipyard.py +++ b/shipyard.py @@ -19,6 +19,6 @@ def export(data, filename): h = open(filename, 'wt') h.write(header) - for (name,fdevid) in [(ship_map.get(ship['name'].lower(), ship['name']), ship['id']) for ship in (data['lastStarport']['ships'].get('shipyard_list') or {}).values() + data['lastStarport']['ships'].get('unavailable_list')]: + for (name,fdevid) in [(ship_map.get(ship['name'].lower(), ship['name']), ship['id']) for ship in list((data['lastStarport']['ships'].get('shipyard_list') or {}).values()) + data['lastStarport']['ships'].get('unavailable_list')]: h.write('%s,%s,%s,%s\n' % (rowheader, name, fdevid, data['timestamp'])) h.close() diff --git a/stats.py b/stats.py index 58f30d05..c8b3daa0 100644 --- a/stats.py +++ b/stats.py @@ -145,10 +145,10 @@ def status(data): def export_status(data, filename): - h = csv.writer(open(filename, 'wb')) + h = csv.writer(open(filename, 'w')) h.writerow(['Category', 'Value']) for thing in status(data): - h.writerow([x.encode('utf-8') for x in thing]) + h.writerow([x for x in thing]) # Returns id,name,shipName,system,station,value @@ -168,10 +168,10 @@ def ships(data): return [ (str(ship['id']), ship_map.get(ship['name'].lower(), ship['name']), ship.get('shipName', ''), ship['starsystem']['name'], ship['station']['name'], str(ship['value']['total'])) for ship in ships if ship] def export_ships(data, filename): - h = csv.writer(open(filename, 'wb')) + h = csv.writer(open(filename, 'w')) h.writerow(['Id', 'Ship', 'Name', 'System', 'Station', 'Value']) for thing in ships(data): - h.writerow([x.encode('utf-8') for x in thing]) + h.writerow([x for x in thing]) class StatsDialog():