From 0cfb1e3dcf038de6062ea7290767a31c6d285271 Mon Sep 17 00:00:00 2001 From: raylu Date: Sat, 28 Feb 2015 03:46:09 -0800 Subject: station trading script --- trading.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 trading.py diff --git a/trading.py b/trading.py new file mode 100755 index 0000000..778e9a0 --- /dev/null +++ b/trading.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 + +from xml.etree import ElementTree + +import oursql +import requests + +conn = oursql.connect(db='eve', user='eve', passwd='eve') +rs = requests.session() + +def get_systemid(name): + with conn as c: + c.execute('SELECT solarSystemID FROM mapSolarSystems WHERE solarSystemName LIKE ?', + (name,)) + return c.fetchone()[0] + +def iter_items(): + with conn as c: + # metaGroupID's: + # NULL or 1: Tech I + # 2: Tech II + # 3: storyline + # 4: faction + # 5: officer + # 6: deadspace + # 14: Tech III + c.execute(''' + SELECT invTypes.typeID, typeName FROM invTypes + LEFT JOIN invMetaTypes ON invMetaTypes.typeID = invTypes.typeID + WHERE marketGroupID IS NOT NULL AND metaGroupID != 5 + ''') + while True: + r = c.fetchone() + if r is None: + break + yield r + +def get_prices(typeid, systemid): + url = 'http://api.eve-central.com/api/marketstat?typeid=%d&usesystem=%d' % (typeid, systemid) + response = rs.get(url, stream=True) + xml = ElementTree.fromstring(response.text) + parent = xml.find('marketstat').find('type') + + buy = parent.findall('buy')[0].find('max') + bid = float(buy.text) + + sell = parent.find('sell').find('min') + ask = float(sell.text) + + volume = parent.find('all').find('volume') + vol = int(volume.text) + + return bid, ask, vol + +def main(): + for system in ['amarr', 'rens', 'dodixie', 'hek']: + systemid = get_systemid(system) + with open(system, 'w') as f: + for typeid, name in iter_items(): + bid, ask, vol = get_prices(typeid, systemid) + score = (ask - bid) * vol + f.write('%f\t%f\t%f\t%d\t%s\n' % (score, ask, bid, vol, name)) + +if __name__ == '__main__': + main() -- cgit v1.2.3