1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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()
|