Skip to content

Commit

Permalink
Converted 'buy' command
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Smith committed Nov 4, 2014
1 parent f59f449 commit 92426b9
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions commands/buy_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,31 @@ def genStationIDs():
results.summary.sort = "Dist"
results.rows.sort(key=lambda result: result.dist)

print(results.rows)

return None
return results

#######################################################################
## Transform result set into output

def render(results, cmdenv, tdb):
from formatting import RowFormat, ColumnFormat

### TODO: Implement

# maxStnNameLen = len(max(results, key=lambda result: len(result.station.dbname) + len(result.station.system.dbname) + 1).station.name())
# cmdenv.printHeading("{station:<{maxStnLen}} {cost:>10} {stock:>10} {dist:{distFmt}}".format(
# station="Station", cost="Cost", stock="Stock",
# dist="Ly" if near else "",
# maxStnLen=maxStnNameLen,
# distFmt=">6" if near else ""
# ))
# for result in results:
# print("{station:<{maxStnLen}} {cost:>10n} {stock:>10} {dist:{distFmt}}".format(
# station=result.station.name(),
# cost=result.cost,
# stock="{:n}".format(result.stock) if result.stock > 0 else "",
# dist=result.dist if near else "",
# maxStnLen=maxStnNameLen,
# distFmt=">6.2f" if near else ""
# ))
longestNamed = max(results.rows, key=lambda result: len(result.station.name()))
longestNameLen = len(longestNamed.station.name())

stnRowFmt = RowFormat()
stnRowFmt.addColumn('Station', '<', longestNameLen,
key=lambda row: row.station.name())
stnRowFmt.addColumn('Cost', '>', 10, 'n',
key=lambda row: row.price)
stnRowFmt.addColumn('Stock', '>', 10,
key=lambda row: '{:n}'.format(row.stock) if row.stock >= 0 else 'unknown')
if cmdenv.nearSystem:
stnRowFmt.addColumn('Dist', '>', 6, '.2f',
key=lambda row: row.dist)

if cmdenv.detail:
heading, underline = stnRowFmt.heading()
print(heading, underline, sep='\n')

for row in results.rows:
print(stnRowFmt.format(row))

0 comments on commit 92426b9

Please sign in to comment.