1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-15 00:30:33 +03:00

Replaced modulo string interpolation with .format

.format is newer and easier to read
This commit is contained in:
A_D 2020-07-10 05:44:29 +02:00
parent 9581ead7cc
commit 82fce9e8c0
No known key found for this signature in database
GPG Key ID: 4BE9EB7DF45076C4

View File

@ -156,9 +156,9 @@ def export(data, filename=None):
elif slot in loadout: elif slot in loadout:
for name in loadout[slot]: for name in loadout[slot]:
string += '%s: %s\n' % (slot, name) string += '{}: {}\n'.format(slot, name)
string += '---\nCargo : %d T\nFuel : %d T\n' % (cargo, fuel) string += '---\nCargo : {} T\nFuel : {} T\n'.format(cargo, fuel)
# Add mass and range # Add mass and range
assert data['ship']['name'].lower() in companion.ship_map, data['ship']['name'] assert data['ship']['name'].lower() in companion.ship_map, data['ship']['name']
@ -167,11 +167,14 @@ def export(data, filename=None):
try: try:
# https://github.com/cmmcleod/coriolis/blob/master/app/js/shipyard/module-shipyard.js#L184 # https://github.com/cmmcleod/coriolis/blob/master/app/js/shipyard/module-shipyard.js#L184
mass += ships[companion.ship_map[data['ship']['name'].lower()]]['hullMass'] mass += ships[companion.ship_map[data['ship']['name'].lower()]]['hullMass']
string += 'Mass : %.2f T empty\n %.2f T full\n' % (mass, mass + fuel + cargo) string += 'Mass : {:.2f} T empty\n {:.2f} T full\n'.format(mass, mass + fuel + cargo)
multiplier = pow(min(fuel, fsd['maxfuel']) / fsd['fuelmul'], 1.0 / fsd['fuelpower']) * fsd['optmass'] multiplier = pow(min(fuel, fsd['maxfuel']) / fsd['fuelmul'], 1.0 / fsd['fuelpower']) * fsd['optmass']
string += 'Range : %.2f LY unladen\n %.2f LY laden\n' % (
string += 'Range : {:.2f} LY unladen\n {:.2f} LY laden\n'.format(
multiplier / (mass + fuel) + jumpboost, multiplier / (mass + fuel) + jumpboost,
multiplier / (mass + fuel + cargo) + jumpboost) multiplier / (mass + fuel + cargo) + jumpboost
)
except Exception: except Exception:
if __debug__: if __debug__:
@ -193,6 +196,9 @@ def export(data, filename=None):
return # same as last time - don't write return # same as last time - don't write
# Write # Write
filename = join(config.get('outdir'), '%s.%s.txt' % (ship, time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)))) filename = join(config.get('outdir'), '{}.{}.txt'.format(
ship, time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)))
)
with open(filename, 'wt') as h: with open(filename, 'wt') as h:
h.write(string) h.write(string)