From 785503e0e70f528c721c979e4146a924908d0a99 Mon Sep 17 00:00:00 2001 From: raylu Date: Fri, 17 Aug 2012 02:09:08 -0700 Subject: handle None mats, write to file --- manufacturing.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/manufacturing.py b/manufacturing.py index fb5d407..acf360a 100755 --- a/manufacturing.py +++ b/manufacturing.py @@ -66,7 +66,7 @@ def get_mats(typeid): break mat_typeid, quantity = r if mat_typeid not in minerals.keys(): - return None + return try: mats[mat_typeid] += quantity except KeyError: @@ -89,6 +89,8 @@ def get_prices(typeid, systemid): def calc_margin(typeid, systemid): mats = get_mats(typeid) + if mats is None: + return cost = 0 for mtypeid, quantity in mats.iteritems(): try: @@ -116,7 +118,10 @@ prices = {} systemid = get_systemid(system_name) for typeid in minerals.iterkeys(): prices[typeid] = get_prices(typeid, systemid) -for typeid, name in iter_blueprints(): - margin = calc_margin(typeid, systemid) - if margin is not None: - print '%0.2f\t%s' % (margin, name) +with open(system_name, 'w') as f: + for typeid, name in iter_blueprints(): + margin = calc_margin(typeid, systemid) + if margin is not None: + line = '%0.2f\t%s' % (margin, name) + print line + f.write(line + '\n') -- cgit v1.2.3