forked from farshield/shortcircuit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Valtyr Farshield
committed
Jun 5, 2016
1 parent
b506234
commit 4415dcc
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
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
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() |
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
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