mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-12 15:27:14 +03:00
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 <dict>.values().
This commit is contained in:
parent
69bcb9d6fa
commit
27d7265c86
2
EDMC.py
2
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)
|
||||
|
@ -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'
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
8
stats.py
8
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():
|
||||
|
Loading…
x
Reference in New Issue
Block a user