summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmanufacturing.py44
1 files changed, 16 insertions, 28 deletions
diff --git a/manufacturing.py b/manufacturing.py
index 894e580..f3ee03d 100755
--- a/manufacturing.py
+++ b/manufacturing.py
@@ -4,9 +4,9 @@ import oursql
import requests
import urllib2
from xml.dom import minidom
+import xml.parsers.expat
-system_name = 'amarr'
-#system_name = 'jita'
+system_name = 'jita'
conn = oursql.connect(db='eve', user='eve', passwd='eve')
rs = requests.session(headers={'User-Agent': 'http://git.raylu.net/eve/'})
@@ -67,8 +67,6 @@ def get_mats(typeid):
if r is None:
break
mat_typeid, quantity = r
- if mat_typeid not in minerals.keys():
- return
try:
mats[mat_typeid] += quantity
except KeyError:
@@ -77,7 +75,13 @@ def get_mats(typeid):
finally:
curs.close()
-def get_prices(typeid, systemid):
+systemid = get_systemid(system_name)
+prices = {}
+def get_prices(typeid):
+ global prices
+ if typeid in prices:
+ return prices[typeid]
+
# &regionlimit=%d
url = 'http://api.eve-central.com/api/marketstat?typeid=%d&usesystem=%d' % (typeid, systemid)
xml = minidom.parseString(rs.get(url).text)
@@ -90,45 +94,29 @@ def get_prices(typeid, systemid):
sell_min = sell.getElementsByTagName('min')[0]
ask = float(sell_min.childNodes[0].data)
+ prices[typeid] = (bid, ask)
return bid, ask
-def calc_margin(typeid, systemid):
+def calc_margin(typeid):
mats = get_mats(typeid)
if mats is None:
return
cost = 0
for mtypeid, quantity in mats.iteritems():
- try:
- cost += prices[mtypeid][1] * quantity
- except KeyError:
- return
+ cost += get_prices(mtypeid)[1] * quantity
if cost == 0:
return
- sell_value = get_prices(typeid, systemid)[0]
+ sell_value = get_prices(typeid)[0]
profit = sell_value - cost
margin = profit / cost
return margin
-minerals = {
- 34: 'Tritanium',
- 35: 'Pyerite',
- 36: 'Mexallon',
- 40: 'Megacyte',
- 37: 'Isogen',
- 38: 'Nocxium',
- 39: 'Zydrine',
- }
-prices = {}
-
-systemid = get_systemid(system_name)
-for typeid in minerals.iterkeys():
- prices[typeid] = get_prices(typeid, systemid)
with open(system_name, 'w') as f:
for typeid, name in iter_blueprints():
try:
- margin = calc_margin(typeid, systemid)
- except Exception as e:
- print repr(e)
+ margin = calc_margin(typeid)
+ except xml.parsers.expat.ExpatError:
+ pass
else:
if margin is not None:
line = '%0.2f\t%s' % (margin, name)