diff --git a/commands/market_cmd.py b/commands/market_cmd.py index 815c2cd1..72afc250 100644 --- a/commands/market_cmd.py +++ b/commands/market_cmd.py @@ -79,7 +79,7 @@ def run(results, cmdenv, tdb): row = ResultRow() row.item = item row.buyCr = int(next(it) or 0) - row.avgBuy = tdb.avgBuying[item.ID] + row.avgBuy = tdb.avgBuying.get(item.ID, 0) units, level = int(next(it) or 0), int(next(it) or 0) row.buyUnits = units row.buyLevel = level @@ -89,7 +89,7 @@ def run(results, cmdenv, tdb): else: hasBuy = False row.sellCr = int(next(it) or 0) - row.avgSell = tdb.avgSelling[item.ID] + row.avgSell = tdb.avgSelling.get(item.ID, 0) units, level = int(next(it) or 0), int(next(it) or 0) row.sellUnits = units row.sellLevel = level diff --git a/commands/station_cmd.py b/commands/station_cmd.py index 09f7e09d..d047024d 100644 --- a/commands/station_cmd.py +++ b/commands/station_cmd.py @@ -347,7 +347,7 @@ class ItemTrade(object): def __init__(self, ID, price, avgAgainst): self.ID, self.item = ID, tdb.itemByID[ID] self.price = int(price) - self.avgTrade = avgAgainst[ID] + self.avgTrade = avgAgainst.get(ID, 0) # Look up all selling and buying by the station selling, buying = [], [] @@ -358,9 +358,9 @@ def __init__(self, ID, price, avgAgainst): AND (demand_price > 10 or supply_price > 10) """, [station.ID]) for ID, demand_price, supply_price in cur: - if demand_price > 10 and avgSell[ID] > 10: + if demand_price > 10 and avgSell.get(ID, 0) > 10: buying.append(ItemTrade(ID, demand_price, avgSell)) - if supply_price > 10 and avgBuy[ID] > 10: + if supply_price > 10 and avgBuy.get(ID, 0) > 10: selling.append(ItemTrade(ID, supply_price, avgBuy)) selling.sort( key=lambda item: item.price - item.avgTrade, diff --git a/commands/trade_cmd.py b/commands/trade_cmd.py index a9fa6456..e33652fb 100644 --- a/commands/trade_cmd.py +++ b/commands/trade_cmd.py @@ -79,24 +79,24 @@ def render(results, cmdenv, tdb): key=lambda row: row.costCr) if cmdenv.detail > 1: rowFmt.addColumn('AvgCost', '>', 10, - key=lambda row: tdb.avgSelling[row.item.ID] - ) + key=lambda row: tdb.avgSelling.get(row.item.ID, 0) + ) rowFmt.addColumn('Buying', '>', 10, - key=lambda row: row.costCr + row.gainCr - ) + key=lambda row: row.costCr + row.gainCr + ) rowFmt.addColumn('AvgBuy', '>', 10, - key=lambda row: tdb.avgBuying[row.item.ID] - ) + key=lambda row: tdb.avgBuying.get(row.item.ID, 0) + ) if cmdenv.detail: rowFmt.addColumn('Supply', '>', 10, - key=lambda row: '{:n}'.format(row.supply) if row.supply >= 0 else '?') + key=lambda row: '{:n}'.format(row.supply) if row.supply >= 0 else '?') rowFmt.addColumn('Demand', '>', 10, - key=lambda row: '{:n}'.format(row.demand) if row.demand >= 0 else '?') + key=lambda row: '{:n}'.format(row.demand) if row.demand >= 0 else '?') rowFmt.addColumn('SrcAge', '>', 8, '.2f', - key=lambda row: (row.srcAge / 86400)) + key=lambda row: (row.srcAge / 86400)) rowFmt.addColumn('DstAge', '>', 8, '.2f', - key=lambda row: (row.dstAge / 86400)) + key=lambda row: (row.dstAge / 86400)) if not cmdenv.quiet: heading, underline = rowFmt.heading()