Skip to content

Commit

Permalink
EveScout module added
Browse files Browse the repository at this point in the history
  • Loading branch information
Valtyr Farshield committed Jun 5, 2016
1 parent b506234 commit 4415dcc
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/pathfinder/model/evescout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# evescout.py

import requests
from datetime import datetime
from solarmap import SolarMap


class EveScout:
"""
Eve Scout Thera Connections
"""

def __init__(self, eve_db, url="https://www.eve-scout.com/api/wormholes"):
self.eve_db = eve_db
self.evescout_url = url

def augment_map(self, solar_map):
headers = {
"User-Agent": "Pathfinder"
}
result = requests.get(
url=self.evescout_url,
headers=headers
)

if result.status_code == 200:
json_response = result.json()
for row in json_response:
# Retrieve signature meta data
source = row['sourceSolarSystem']['id']
dest = row['destinationSolarSystem']['id']
sig_source = row['signatureId']
code_source = row['sourceWormholeType']['name']
sig_dest = row['wormholeDestinationSignatureId']
code_dest = row['destinationWormholeType']['name']
if row['wormholeEol'] == 'stable':
wh_life = 1
else:
wh_life = 0
if row['wormholeEol'] == 'stable':
wh_mass = 2
elif row['wormholeEol'] == 'destab':
wh_mass = 1
else:
wh_mass = 0

# Compute time elapsed from this moment to when the signature was updated
last_modified = datetime.strptime(row['updatedAt'][:-5], "%Y-%m-%dT%H:%M:%S")
delta = datetime.utcnow() - last_modified
time_elapsed = round(delta.total_seconds() / 3600.0, 1)

if source != 0 and dest != 0:
# Determine wormhole size
size_result1 = self.eve_db.get_whsize_by_code(code_source)
size_result2 = self.eve_db.get_whsize_by_code(code_dest)
if size_result1 in [0, 1, 2, 3]:
wh_size = size_result1
elif size_result2 in [0, 1, 2, 3]:
wh_size = size_result2
else:
# Wormhole codes are unknown => determine size based on class of wormholes
wh_size = self.eve_db.get_whsize_by_system(source, dest)

solar_map.add_connection(
source,
dest,
SolarMap.WORMHOLE,
[sig_source, code_source, sig_dest, code_dest, wh_size, wh_life, wh_mass, time_elapsed],
)


def main():
evescout = EveScout(None)
evescout.augment_map(None)

if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions src/pathfinder/model/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from evedb import EveDb
from solarmap import SolarMap
from evescout import EveScout
from tripwire import Tripwire


Expand All @@ -25,6 +26,10 @@ def tripwire_set_login(self, trip_url, trip_user, trip_pass):
self.trip_user = trip_user
self.trip_pass = trip_pass

def evescout_augment(self, solar_map):
evescout = EveScout(self.eve_db)
evescout.augment_map(solar_map)

def tripwire_augment(self, solar_map):
trip = Tripwire(self.eve_db, self.trip_user, self.trip_pass, self.trip_url)
return trip.augment_map(solar_map)
Expand Down
1 change: 1 addition & 0 deletions src/pathfinder/model/navprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ def process(self):
solar_map = self.nav.eve_db.get_solar_map()
connections = self.nav.tripwire_augment(solar_map)
if connections > 0:
self.nav.evescout_augment(solar_map)
self.nav.solar_map = solar_map
self.finished.emit(connections)

0 comments on commit 4415dcc

Please sign in to comment.