summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorraylu <raylu@mixpanel.com>2012-08-17 02:09:08 -0700
committerraylu <raylu@mixpanel.com>2012-08-17 02:09:08 -0700
commit785503e0e70f528c721c979e4146a924908d0a99 (patch)
treef1782fe59ba50e752c4f5cc7bc7707e66962122f
parenteca257179dc9336103641b8999f7730d8e67b4f6 (diff)
downloadeve-785503e0e70f528c721c979e4146a924908d0a99.tar.xz
handle None mats, write to file
-rwxr-xr-xmanufacturing.py15
1 files 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')