-
-
Save farshield/0b525fac05b39d4415d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# thehunter.py | |
import time | |
import urllib2 | |
import gzip | |
import json | |
from StringIO import StringIO | |
SHIPS = [ | |
29988, # Proteus | |
29986, # Legion | |
29984, # Tengu | |
29990, # Loki | |
] | |
IGNORE_WEAPONS = False | |
WEAPONS = [ | |
15963, # Imperial Navy Large EMP Smartbomb | |
3993, # Large EMP Smartbomb I | |
3995, # Large EMP Smartbomb II | |
15947, # Ammatar Navy Large EMP Smartbomb | |
14188, # Dark Blood Large EMP Smartbomb | |
14190, # True Sansha Large EMP Smartbomb | |
28545, # Khanid Navy Large EMP Smartbomb | |
] | |
def zkill_fetch(page_nr): | |
headers = { | |
"User-Agent" : "Your name, Mail: Your mail", | |
"Accept-encoding": "gzip" | |
} | |
url = "https://zkillboard.com/api/w-space/losses/solo/shipID/607,605,29248,586,11172,11192,11188,11182/page/{}/".format( | |
page_nr, | |
) | |
try: | |
request = urllib2.Request(url, None, headers) | |
response = urllib2.urlopen(request) | |
except urllib2.URLError as e: | |
print "[Error]", e.reason | |
return None | |
if response.info().get("Content-Encoding") == "gzip": | |
buf = StringIO(response.read()) | |
f = gzip.GzipFile(fileobj=buf) | |
data = f.read() | |
else: | |
data = response.read() | |
return data | |
def analyze_data(max_page): | |
attackers = {} | |
solar_systems = {} | |
for page in range(max_page): | |
data = zkill_fetch(page + 1) | |
# try to parse JSON received from server | |
try: | |
parsed_json = json.loads(data) | |
except ValueError as e: | |
print "[Error]", e | |
return | |
for killmail in parsed_json: | |
if killmail['attackers'][0]['shipTypeID'] in SHIPS: | |
if killmail['attackers'][0]['weaponTypeID'] in WEAPONS or IGNORE_WEAPONS: | |
attacker_name = killmail['attackers'][0]['characterName'] | |
attacker_corp = killmail['attackers'][0]['corporationName'] | |
solar_system = killmail['solarSystemID'] | |
kill_time = killmail['killTime'] | |
print "{},{},{},{}".format(attacker_name, attacker_corp, solar_system, kill_time) | |
if attacker_name in attackers.keys(): | |
attackers[attacker_name] += 1 | |
else: | |
attackers[attacker_name] = 1 | |
if solar_system in solar_systems.keys(): | |
solar_systems[solar_system] += 1 | |
else: | |
solar_systems[solar_system] = 1 | |
time.sleep(0.1) | |
print "" | |
print "------------------------------------------------------------------------------" | |
for w in sorted(attackers, key=attackers.get, reverse=True): | |
print w, attackers[w] | |
print "" | |
print "------------------------------------------------------------------------------" | |
for w in sorted(solar_systems, key=solar_systems.get, reverse=True): | |
print w, solar_systems[w] | |
def main(): | |
analyze_data(30) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment