1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 16:27:13 +03:00
EDMarketConnector/shipyard.py
Jonathan Harris 98059e1d18 Add shipyard.py.
Fixes #42.
Should have been committed with b0f60af.
2015-11-22 23:05:26 +00:00

53 lines
2.1 KiB
Python

# Export list of ships as CSV
import time
from config import config
ship_map = {
'adder' : 'Adder',
'anaconda' : 'Anaconda',
'asp' : 'Asp',
'cobramkiii' : 'Cobra Mk III',
'diamondback' : 'Diamondback Scout',
'diamondbackxl' : 'Diamondback Explorer',
'eagle' : 'Eagle',
'empire_courier' : 'Imperial Courier',
'empire_eagle' : 'Imperial Eagle',
'empire_fighter' : 'Imperial Fighter',
'empire_trader' : 'Imperial Clipper',
'federation_dropship' : 'Federal Dropship',
'federation_dropship_mkii' : 'Federal Assault Ship',
'federation_gunship' : 'Federal Gunship',
'federation_fighter' : 'F63 Condor',
'ferdelance' : 'Fer-de-Lance',
'hauler' : 'Hauler',
'orca' : 'Orca',
'python' : 'Python',
'sidewinder' : 'Sidewinder',
'type6' : 'Type-6 Transporter',
'type7' : 'Type-7 Transporter',
'type9' : 'Type-9 Heavy',
'viper' : 'Viper',
'vulture' : 'Vulture',
}
def export(data, filename):
querytime = config.getint('querytime') or int(time.time())
assert data['lastSystem'].get('name')
assert data['lastStarport'].get('name')
assert data['lastStarport'].get('ships')
timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(querytime))
header = 'System,Station,Ship,Date\n'
rowheader = '%s,%s' % (data['lastSystem']['name'], data['lastStarport']['name'])
h = open(filename, 'wt')
h.write(header)
for name in [ship_map[ship['name'].lower()] for ship in (data['lastStarport']['ships'].get('shipyard_list') or {}).values() + data['lastStarport']['ships'].get('unavailable_list') if ship['name'].lower() in ship_map]:
h.write('%s,%s,%s\n' % (rowheader, name, timestamp))
h.close()