mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-13 15:57:14 +03:00
Switch EDShipyard import to Loadout event
This commit is contained in:
parent
2aadc17a9d
commit
88f323d36e
@ -709,6 +709,14 @@ class AppWindow:
|
||||
if not monitor.cmdr or not monitor.mode:
|
||||
return False # In CQC - do nothing
|
||||
|
||||
if config.getint('shipyard') == config.SHIPYARD_EDSHIPYARD:
|
||||
return edshipyard.url(monitor.is_beta)
|
||||
elif config.getint('shipyard') == config.SHIPYARD_CORIOLIS:
|
||||
pass # Fall through
|
||||
else:
|
||||
assert False, config.getint('shipyard')
|
||||
return False
|
||||
|
||||
self.status['text'] = _('Fetching data...')
|
||||
self.w.update_idletasks()
|
||||
try:
|
||||
@ -734,13 +742,7 @@ class AppWindow:
|
||||
self.status['text'] = _('Error: Frontier server is lagging') # Raised when Companion API server is returning old data, e.g. when the servers are too busy
|
||||
else:
|
||||
self.status['text'] = ''
|
||||
if config.getint('shipyard') == config.SHIPYARD_EDSHIPYARD:
|
||||
return edshipyard.url(data, monitor.is_beta)
|
||||
elif config.getint('shipyard') == config.SHIPYARD_CORIOLIS:
|
||||
return coriolis.url(data, monitor.is_beta)
|
||||
else:
|
||||
assert False, config.getint('shipyard')
|
||||
return False
|
||||
return coriolis.url(data, monitor.is_beta)
|
||||
|
||||
def cooldown(self):
|
||||
if time() < self.holdofftime:
|
||||
|
@ -13,6 +13,7 @@ import gzip
|
||||
from config import config
|
||||
import companion
|
||||
import outfitting
|
||||
from monitor import monitor
|
||||
|
||||
# Map API ship names to E:D Shipyard ship names
|
||||
ship_map = dict(companion.ship_map)
|
||||
@ -162,9 +163,11 @@ def export(data, filename=None):
|
||||
|
||||
|
||||
# Return a URL for the current ship
|
||||
def url(data, is_beta):
|
||||
def url(is_beta):
|
||||
|
||||
string = json.dumps(companion.ship(data), ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8') # most compact representation
|
||||
string = json.dumps(monitor.ship(), ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8') # most compact representation
|
||||
if not string:
|
||||
return False
|
||||
|
||||
out = StringIO.StringIO()
|
||||
with gzip.GzipFile(fileobj=out, mode='w') as f:
|
||||
|
19
monitor.py
19
monitor.py
@ -625,5 +625,24 @@ class EDLogs(FileSystemEventHandler):
|
||||
return False
|
||||
|
||||
|
||||
# Return a subset of the received data describing the current ship as a Loadout event
|
||||
def ship(self):
|
||||
if not self.state['Modules']:
|
||||
return None
|
||||
|
||||
d = OrderedDict([
|
||||
('timestamp', strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())),
|
||||
('event', 'Loadout'),
|
||||
('Ship', self.state['ShipType']),
|
||||
('ShipID', self.state['ShipID']),
|
||||
])
|
||||
for thing in ['ShipName', 'ShipIdent', 'HullValue', 'ModulesValue', 'Rebuy']:
|
||||
if self.state[thing]:
|
||||
d[thing] = self.state[thing]
|
||||
d['Modules'] = self.state['Modules'].values()
|
||||
|
||||
return d
|
||||
|
||||
|
||||
# singleton
|
||||
monitor = EDLogs()
|
||||
|
@ -34,6 +34,7 @@ this.session = requests.Session()
|
||||
this.queue = Queue() # Items to be sent to EDSM by worker thread
|
||||
this.discardedEvents = [] # List discarded events from EDSM
|
||||
this.lastship = None # Description of last ship that we sent to EDSM
|
||||
this.lastloadout = None # Description of last ship that we sent to EDSM
|
||||
this.lastlookup = False # whether the last lookup succeeded
|
||||
|
||||
# Game state
|
||||
@ -235,6 +236,14 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
|
||||
this.queue.put((cmdr, entry))
|
||||
|
||||
if entry['event'] == 'Loadout' and 'EDShipyard' not in this.discardedEvents:
|
||||
url = edshipyard.url(is_beta)
|
||||
if this.lastloadout != url:
|
||||
this.lastloadout = url
|
||||
this.queue.put((cmdr, {
|
||||
'event': 'EDShipyard', 'timestamp': entry['timestamp'], '_shipId': state['ShipID'], 'url': this.lastloadout
|
||||
}))
|
||||
|
||||
|
||||
# Update system data
|
||||
def cmdr_data(data, is_beta):
|
||||
@ -262,10 +271,6 @@ def cmdr_data(data, is_beta):
|
||||
this.queue.put((cmdr, {
|
||||
'event': 'Coriolis', 'timestamp': timestamp, '_shipId': data['ship']['id'], 'url': coriolis.url(data, is_beta)
|
||||
}))
|
||||
if 'EDShipyard' not in this.discardedEvents:
|
||||
this.queue.put((cmdr, {
|
||||
'event': 'EDShipyard', 'timestamp': timestamp, '_shipId': data['ship']['id'], 'url': edshipyard.url(data, is_beta)
|
||||
}))
|
||||
this.lastship = ship
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user