Skip to content

Instantly share code, notes, and snippets.

@arivero
Last active August 29, 2015 13:58
Show Gist options
  • Save arivero/9938726 to your computer and use it in GitHub Desktop.
Save arivero/9938726 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
import sys
import re
import time
from itertools import combinations
from collections import Counter,defaultdict
from datetime import datetime
import urllib2
import MySQLdb
db = MySQLdb.connect(db="EveOnline", host="localhost", charset='utf8')
name={}
group={}
c = db.cursor()
c.execute("SELECT t.typeID, typeName, groupID from invTypes t join (select distinct materialTypeID from invTypeMaterials) mat on (mat.materialTypeID=t.typeID)")
for result in c.fetchall():
name[result[0]]=result[1]
group[result[0]]=result[2]
c.close()
c = db.cursor()
decompose=defaultdict(dict)
c.execute("SELECT typeID,materialTypeID, quantity from invTypeMaterials");
for result in c.fetchall():
decompose[result[0]][result[1]]=result[2]
c.close()
#we need to add planetary
c = db.cursor()
c.execute("select ou.typeid, inp.typeid, inp.quantity/ou.quantity from planetSchematicsTypeMap inp, planetSchematicsTypeMap ou where inp.isInput=1 and ou.isInput=0 and ou.schematicID=inp.schematicID order by inp.schematicID");
for result in c.fetchall():
decompose[result[0]][result[1]]=result[2]
c.close()
c = db.cursor()
c.execute("SELECT t.typeID, typeName, groupID from invTypes t join (SELECT distinct typeid from planetSchematicsTypeMap where isInput=1) mat on (mat.typeid=t.typeID)")
for result in c.fetchall():
name[result[0]]=result[1]
group[result[0]]=result[2]
c.close()
#ok, and now we need decompose everything
fulldecompose=defaultdict(dict)
def composition(x,q):
if x in decompose:
tally=Counter()
for component in decompose[x]:
quantity=decompose[x][component]
tally+=Counter(composition(component,q*quantity))
return tally
else:
return {x:q}
fulldecompose=defaultdict(dict)
for x in decompose:
xdict=composition(x,1)
fulldecompose[x]=xdict
#from Queue import Queue,Empty
#q=Queue()
#groups in killmail producing some material at all
Groups=[25,26,27,28,30,31,324,358,365,380,
404,417,419,420,426,430,438,439,440,441,443,449,463,471,473,485,
513,540,541,543,547,659,709,830,831,832,833,834,837,883,893,894,898,
900,902,906,941,963,1012,1022,1025,1201,1202,1246,1247,1249,1250,1273,1275,1276]
xmlTotalKills="https://api.eveonline.com/Map/Kills.xml.aspx"
zkillURL="https://zkillboard.com/api/no-attackers/api-only/no-items/losses/groupID/%s/pastSeconds/3600/"
Agent="YOUR AGENT NAME HERE. "
def cola():
#while True:
for g in Groups:
try:
req = urllib2.Request(zkillURL % g)
req.add_header('User-agent', 'http://www.python.org/')
r = urllib2.urlopen(req)
j=json.load(r)
print j
except urllib2.URLError:
print "ummh"
time.sleep(60)
continue
for dato in j:
yield dato
time.sleep(12)
klist=cola()
materials=Counter()
fullmaterials=Counter()
for kill in klist:
victim=kill["victim"]
print "victim with ship type ", victim["shipTypeID"], " took ", victim["damageTaken"], " damage"
c = db.cursor()
c.execute("SELECT materialTypeID, quantity from invTypeMaterials where typeID="+str(victim["shipTypeID"]))
for result in c.fetchall():
materials[result[0]]+=result[1]
c.close()
fullmaterials += Counter(fulldecompose[int(victim["shipTypeID"])])
print "==========total wasted ========="
for m in materials:
print group[m],name[m], materials[m]
print "------fully reduced----"
for m in fullmaterials:
print group[m],name[m], fullmaterials[m]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment