Browse Source

handle None mats, write to file

raylu 13 years ago
parent
commit
785503e0e7
1 changed files with 10 additions and 5 deletions
  1. 10 5
      manufacturing.py

+ 10 - 5
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')