summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmanufacturing.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/manufacturing.py b/manufacturing.py
index acf360a..894e580 100755
--- a/manufacturing.py
+++ b/manufacturing.py
@@ -1,12 +1,14 @@
#!/usr/bin/env python
import oursql
+import requests
import urllib2
from xml.dom import minidom
system_name = 'amarr'
#system_name = 'jita'
-conn = oursql.connect(db='eve', user='root')
+conn = oursql.connect(db='eve', user='eve', passwd='eve')
+rs = requests.session(headers={'User-Agent': 'http://git.raylu.net/eve/'})
def get_systemid(name):
curs = conn.cursor()
@@ -78,14 +80,17 @@ def get_mats(typeid):
def get_prices(typeid, systemid):
# &regionlimit=%d
url = 'http://api.eve-central.com/api/marketstat?typeid=%d&usesystem=%d' % (typeid, systemid)
- xml = minidom.parse(urllib2.urlopen(url))
+ xml = minidom.parseString(rs.get(url).text)
+
buy = xml.getElementsByTagName('buy')[0]
buy_max = buy.getElementsByTagName('max')[0]
- buy_price = float(buy_max.childNodes[0].data)
+ bid = float(buy_max.childNodes[0].data)
+
sell = xml.getElementsByTagName('sell')[0]
sell_min = sell.getElementsByTagName('min')[0]
- sell_price = float(sell_min.childNodes[0].data)
- return buy_price, sell_price
+ ask = float(sell_min.childNodes[0].data)
+
+ return bid, ask
def calc_margin(typeid, systemid):
mats = get_mats(typeid)
@@ -120,8 +125,12 @@ for typeid in minerals.iterkeys():
prices[typeid] = get_prices(typeid, systemid)
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')
+ try:
+ margin = calc_margin(typeid, systemid)
+ except Exception as e:
+ print repr(e)
+ else:
+ if margin is not None:
+ line = '%0.2f\t%s' % (margin, name)
+ print line
+ f.write(line + '\n')