mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-15 00:30:33 +03:00
Initial work on getting the EDMC.py CLI to work under python3
*) Fix up print usage *) cPickle -> cpickle *) "EDMC.py -p <cmdr name>" appears to have never been properly updated for multi-account support.
This commit is contained in:
parent
a8c0ec3ab9
commit
67708fd090
10
EDMC.py
10
EDMC.py
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# Command-line interface. Requires prior setup through the GUI.
|
# Command-line interface. Requires prior setup through the GUI.
|
||||||
#
|
#
|
||||||
@ -72,7 +72,7 @@ try:
|
|||||||
latest = ' (%s is available)' % items[lastversion]
|
latest = ' (%s is available)' % items[lastversion]
|
||||||
except:
|
except:
|
||||||
pass # Quietly suppress timeouts etc.
|
pass # Quietly suppress timeouts etc.
|
||||||
print '%.2f%s' % (float(''.join(appversion.split('.')[:3])) / 100, latest) # just first three digits
|
print('%.2f%s' % (float(''.join(appversion.split('.')[:3])) / 100, latest)) # just first three digits
|
||||||
sys.exit(EXIT_SUCCESS)
|
sys.exit(EXIT_SUCCESS)
|
||||||
|
|
||||||
if args.j:
|
if args.j:
|
||||||
@ -92,7 +92,7 @@ try:
|
|||||||
monitor.parse_entry(line)
|
monitor.parse_entry(line)
|
||||||
except:
|
except:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
print 'Invalid journal entry "%s"' % repr(line)
|
print('Invalid journal entry "%s"' % repr(line))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.stderr.write("Can't read Journal file: %s\n" % unicode(e).encode('ascii', 'replace'))
|
sys.stderr.write("Can't read Journal file: %s\n" % unicode(e).encode('ascii', 'replace'))
|
||||||
sys.exit(EXIT_SYS_ERR)
|
sys.exit(EXIT_SYS_ERR)
|
||||||
@ -159,9 +159,9 @@ try:
|
|||||||
stats.export_status(data, args.t)
|
stats.export_status(data, args.t)
|
||||||
|
|
||||||
if data['commander'].get('docked'):
|
if data['commander'].get('docked'):
|
||||||
print '%s,%s' % (data.get('lastSystem', {}).get('name', 'Unknown'), data.get('lastStarport', {}).get('name', 'Unknown'))
|
print('%s,%s' % (data.get('lastSystem', {}).get('name', 'Unknown'), data.get('lastStarport', {}).get('name', 'Unknown')))
|
||||||
else:
|
else:
|
||||||
print data.get('lastSystem', {}).get('name', 'Unknown')
|
print(data.get('lastSystem', {}).get('name', 'Unknown'))
|
||||||
|
|
||||||
if (args.m or args.o or args.s or args.n or args.j):
|
if (args.m or args.o or args.s or args.n or args.j):
|
||||||
if not data['commander'].get('docked'):
|
if not data['commander'].get('docked'):
|
||||||
|
22
collate.py
22
collate.py
@ -58,7 +58,7 @@ def addcommodities(data):
|
|||||||
for key in sorted(commodities):
|
for key in sorted(commodities):
|
||||||
writer.writerow(commodities[key])
|
writer.writerow(commodities[key])
|
||||||
|
|
||||||
print 'Added %d new commodities' % (len(commodities) - size_pre)
|
print('Added %d new commodities' % (len(commodities) - size_pre))
|
||||||
|
|
||||||
# keep a summary of modules found
|
# keep a summary of modules found
|
||||||
def addmodules(data):
|
def addmodules(data):
|
||||||
@ -83,7 +83,7 @@ def addmodules(data):
|
|||||||
try:
|
try:
|
||||||
new = outfitting.lookup(module, companion.ship_map, True)
|
new = outfitting.lookup(module, companion.ship_map, True)
|
||||||
except:
|
except:
|
||||||
print '%d, %s:' % (module['id'], module['name'])
|
print('%d, %s:' % (module['id'], module['name']))
|
||||||
print_exc(0)
|
print_exc(0)
|
||||||
new = None
|
new = None
|
||||||
if new:
|
if new:
|
||||||
@ -110,7 +110,7 @@ def addmodules(data):
|
|||||||
for key in sorted(modules):
|
for key in sorted(modules):
|
||||||
writer.writerow(modules[key])
|
writer.writerow(modules[key])
|
||||||
|
|
||||||
print 'Added %d new modules' % (len(modules) - size_pre)
|
print('Added %d new modules' % (len(modules) - size_pre))
|
||||||
|
|
||||||
# keep a summary of ships found
|
# keep a summary of ships found
|
||||||
def addships(data):
|
def addships(data):
|
||||||
@ -158,33 +158,33 @@ def addships(data):
|
|||||||
for key in sorted(ships):
|
for key in sorted(ships):
|
||||||
writer.writerow(ships[key])
|
writer.writerow(ships[key])
|
||||||
|
|
||||||
print 'Added %d new ships' % (len(ships) - size_pre)
|
print('Added %d new ships' % (len(ships) - size_pre))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) <= 1:
|
if len(sys.argv) <= 1:
|
||||||
print 'Usage: collate.py [dump.json]'
|
print('Usage: collate.py [dump.json]')
|
||||||
else:
|
else:
|
||||||
# read from dumped json file(s)
|
# read from dumped json file(s)
|
||||||
session = companion.Session()
|
session = companion.Session()
|
||||||
for f in sys.argv[1:]:
|
for f in sys.argv[1:]:
|
||||||
with open(f) as h:
|
with open(f) as h:
|
||||||
print f
|
print(f)
|
||||||
data = json.load(h)
|
data = json.load(h)
|
||||||
if not data['commander'].get('docked'):
|
if not data['commander'].get('docked'):
|
||||||
print 'Not docked!'
|
print('Not docked!')
|
||||||
elif not data.get('lastStarport'):
|
elif not data.get('lastStarport'):
|
||||||
print 'No starport!'
|
print('No starport!')
|
||||||
else:
|
else:
|
||||||
if data['lastStarport'].get('commodities'):
|
if data['lastStarport'].get('commodities'):
|
||||||
addcommodities(data)
|
addcommodities(data)
|
||||||
else:
|
else:
|
||||||
print 'No market'
|
print('No market')
|
||||||
if data['lastStarport'].get('modules'):
|
if data['lastStarport'].get('modules'):
|
||||||
addmodules(data)
|
addmodules(data)
|
||||||
else:
|
else:
|
||||||
print 'No outfitting'
|
print('No outfitting')
|
||||||
if data['lastStarport'].get('ships'):
|
if data['lastStarport'].get('ships'):
|
||||||
addships(data)
|
addships(data)
|
||||||
else:
|
else:
|
||||||
print 'No shipyard'
|
print('No shipyard')
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Export ship loadout in E:D Shipyard plain text format
|
# Export ship loadout in E:D Shipyard plain text format
|
||||||
|
|
||||||
import cPickle
|
import pickle
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import os
|
import os
|
||||||
from os.path import join
|
from os.path import join
|
||||||
@ -40,7 +40,7 @@ slot_map = {
|
|||||||
|
|
||||||
|
|
||||||
# Ship masses
|
# Ship masses
|
||||||
ships = cPickle.load(open(join(config.respath, 'ships.p'), 'rb'))
|
ships = pickle.load(open(join(config.respath, 'ships.p'), 'rb'))
|
||||||
|
|
||||||
|
|
||||||
# Export ship loadout in E:D Shipyard plain text format
|
# Export ship loadout in E:D Shipyard plain text format
|
||||||
@ -107,10 +107,10 @@ def export(data, filename=None):
|
|||||||
if slot.lower().startswith('slot'):
|
if slot.lower().startswith('slot'):
|
||||||
loadout[slot[-1]].append(cr + name)
|
loadout[slot[-1]].append(cr + name)
|
||||||
elif __debug__ and not slot.lower().startswith('planetaryapproachsuite'):
|
elif __debug__ and not slot.lower().startswith('planetaryapproachsuite'):
|
||||||
print 'EDShipyard: Unknown slot %s' % slot
|
print('EDShipyard: Unknown slot %s' % slot)
|
||||||
|
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
if __debug__: print 'EDShipyard: %s' % e
|
if __debug__: print('EDShipyard: %s' % e)
|
||||||
continue # Silently skip unrecognized modules
|
continue # Silently skip unrecognized modules
|
||||||
except:
|
except:
|
||||||
if __debug__: raise
|
if __debug__: raise
|
||||||
|
Loading…
x
Reference in New Issue
Block a user