mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-08 03:12:33 +03:00
Merge pull request #542 from Athanasius/feature/512-eddb-urls-without-pickles
#512 Feature/512 eddb urls without pickles
This commit is contained in:
commit
02c232c279
16
monitor.py
16
monitor.py
@ -82,6 +82,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
self.planet = None
|
self.planet = None
|
||||||
self.system = None
|
self.system = None
|
||||||
self.station = None
|
self.station = None
|
||||||
|
self.station_marketid = None
|
||||||
self.stationtype = None
|
self.stationtype = None
|
||||||
self.coordinates = None
|
self.coordinates = None
|
||||||
self.systemaddress = None
|
self.systemaddress = None
|
||||||
@ -166,7 +167,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
if __debug__:
|
if __debug__:
|
||||||
print('Stopping monitoring Journal')
|
print('Stopping monitoring Journal')
|
||||||
self.currentdir = None
|
self.currentdir = None
|
||||||
self.version = self.mode = self.group = self.cmdr = self.planet = self.system = self.station = self.stationtype = self.stationservices = self.coordinates = self.systemaddress = None
|
self.version = self.mode = self.group = self.cmdr = self.planet = self.system = self.station = self.station_marketid = self.stationtype = self.stationservices = self.coordinates = self.systemaddress = None
|
||||||
self.is_beta = False
|
self.is_beta = False
|
||||||
if self.observed:
|
if self.observed:
|
||||||
self.observed = None
|
self.observed = None
|
||||||
@ -222,6 +223,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
('StarSystem', self.system),
|
('StarSystem', self.system),
|
||||||
('StarPos', self.coordinates),
|
('StarPos', self.coordinates),
|
||||||
('SystemAddress', self.systemaddress),
|
('SystemAddress', self.systemaddress),
|
||||||
|
('Population', self.systempopulation),
|
||||||
])
|
])
|
||||||
if self.planet:
|
if self.planet:
|
||||||
entry['Body'] = self.planet
|
entry['Body'] = self.planet
|
||||||
@ -229,6 +231,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
if self.station:
|
if self.station:
|
||||||
entry['StationName'] = self.station
|
entry['StationName'] = self.station
|
||||||
entry['StationType'] = self.stationtype
|
entry['StationType'] = self.stationtype
|
||||||
|
entry['MarketID'] = self.station_marketid
|
||||||
self.event_queue.append(json.dumps(entry, separators=(', ', ':')))
|
self.event_queue.append(json.dumps(entry, separators=(', ', ':')))
|
||||||
else:
|
else:
|
||||||
self.event_queue.append(None) # Generate null event to update the display (with possibly out-of-date info)
|
self.event_queue.append(None) # Generate null event to update the display (with possibly out-of-date info)
|
||||||
@ -305,6 +308,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
self.planet = None
|
self.planet = None
|
||||||
self.system = None
|
self.system = None
|
||||||
self.station = None
|
self.station = None
|
||||||
|
self.station_marketid = None
|
||||||
self.stationtype = None
|
self.stationtype = None
|
||||||
self.stationservices = None
|
self.stationservices = None
|
||||||
self.coordinates = None
|
self.coordinates = None
|
||||||
@ -344,6 +348,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
self.planet = None
|
self.planet = None
|
||||||
self.system = None
|
self.system = None
|
||||||
self.station = None
|
self.station = None
|
||||||
|
self.station_marketid = None
|
||||||
self.stationtype = None
|
self.stationtype = None
|
||||||
self.stationservices = None
|
self.stationservices = None
|
||||||
self.coordinates = None
|
self.coordinates = None
|
||||||
@ -429,6 +434,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
self.state['Modules'].pop(entry['FromSlot'], None)
|
self.state['Modules'].pop(entry['FromSlot'], None)
|
||||||
elif entry['event'] in ['Undocked']:
|
elif entry['event'] in ['Undocked']:
|
||||||
self.station = None
|
self.station = None
|
||||||
|
self.station_marketid = None
|
||||||
self.stationtype = None
|
self.stationtype = None
|
||||||
self.stationservices = None
|
self.stationservices = None
|
||||||
elif entry['event'] in ['Location', 'FSDJump', 'Docked', 'CarrierJump']:
|
elif entry['event'] in ['Location', 'FSDJump', 'Docked', 'CarrierJump']:
|
||||||
@ -441,8 +447,13 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
elif self.system != entry['StarSystem']:
|
elif self.system != entry['StarSystem']:
|
||||||
self.coordinates = None # Docked event doesn't include coordinates
|
self.coordinates = None # Docked event doesn't include coordinates
|
||||||
self.systemaddress = entry.get('SystemAddress')
|
self.systemaddress = entry.get('SystemAddress')
|
||||||
|
|
||||||
|
if entry['event'] in ['Location', 'FSDJump', 'CarrierJump']:
|
||||||
|
self.systempopulation = entry.get('Population')
|
||||||
|
|
||||||
(self.system, self.station) = (entry['StarSystem'] == 'ProvingGround' and 'CQC' or entry['StarSystem'],
|
(self.system, self.station) = (entry['StarSystem'] == 'ProvingGround' and 'CQC' or entry['StarSystem'],
|
||||||
entry.get('StationName')) # May be None
|
entry.get('StationName')) # May be None
|
||||||
|
self.station_marketid = entry.get('MarketID') # May be None
|
||||||
self.stationtype = entry.get('StationType') # May be None
|
self.stationtype = entry.get('StationType') # May be None
|
||||||
self.stationservices = entry.get('StationServices') # None under E:D < 2.4
|
self.stationservices = entry.get('StationServices') # None under E:D < 2.4
|
||||||
elif entry['event'] == 'ApproachBody':
|
elif entry['event'] == 'ApproachBody':
|
||||||
@ -595,6 +606,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
self.planet = None
|
self.planet = None
|
||||||
self.system = None
|
self.system = None
|
||||||
self.station = None
|
self.station = None
|
||||||
|
self.station_marketid = None
|
||||||
self.stationtype = None
|
self.stationtype = None
|
||||||
self.stationservices = None
|
self.stationservices = None
|
||||||
self.coordinates = None
|
self.coordinates = None
|
||||||
@ -607,6 +619,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
self.planet = None
|
self.planet = None
|
||||||
self.system = None
|
self.system = None
|
||||||
self.station = None
|
self.station = None
|
||||||
|
self.station_marketid = None
|
||||||
self.stationtype = None
|
self.stationtype = None
|
||||||
self.stationservices = None
|
self.stationservices = None
|
||||||
self.coordinates = None
|
self.coordinates = None
|
||||||
@ -651,6 +664,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
('timestamp', strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())),
|
('timestamp', strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())),
|
||||||
('event', 'StartUp'),
|
('event', 'StartUp'),
|
||||||
('Docked', True),
|
('Docked', True),
|
||||||
|
('MarketID', self.station_marketid),
|
||||||
('StationName', self.station),
|
('StationName', self.station),
|
||||||
('StationType', self.stationtype),
|
('StationType', self.stationtype),
|
||||||
('StarSystem', self.system),
|
('StarSystem', self.system),
|
||||||
|
@ -8,6 +8,7 @@ import csv
|
|||||||
import os
|
import os
|
||||||
from os.path import join
|
from os.path import join
|
||||||
import sys
|
import sys
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
from config import config
|
from config import config
|
||||||
|
|
||||||
@ -16,61 +17,62 @@ STATION_UNDOCKED = u'×' # "Station" name to display when not docked = U+00D7
|
|||||||
|
|
||||||
this = sys.modules[__name__] # For holding module globals
|
this = sys.modules[__name__] # For holding module globals
|
||||||
|
|
||||||
# (system_id, is_populated) by system_name
|
this.system_address = None
|
||||||
with open(join(config.respath, 'systems.p'), 'rb') as h:
|
this.system_population = None
|
||||||
this.system_ids = pickle.load(h)
|
this.station_marketid = None # Frontier MarketID
|
||||||
|
|
||||||
# station_id by (system_id, station_name)
|
|
||||||
with open(join(config.respath, 'stations.p'), 'rb') as h:
|
|
||||||
this.station_ids = pickle.load(h)
|
|
||||||
|
|
||||||
|
|
||||||
# Main window clicks
|
# Main window clicks
|
||||||
def system_url(system_name):
|
def system_url(system_address):
|
||||||
if system_id(system_name):
|
if system_address:
|
||||||
return 'https://eddb.io/system/%d' % system_id(system_name)
|
return 'https://eddb.io/system/ed-address/%s' % system_address
|
||||||
else:
|
else:
|
||||||
return None
|
return ''
|
||||||
|
|
||||||
def station_url(system_name, station_name):
|
def station_url(system_name, station_name):
|
||||||
if station_id(system_name, station_name):
|
if this.station_marketid:
|
||||||
return 'https://eddb.io/station/%d' % station_id(system_name, station_name)
|
return 'https://eddb.io/station/market-id/{}'.format(this.station_marketid)
|
||||||
else:
|
else:
|
||||||
return system_url(system_name)
|
return system_url(this.system_address)
|
||||||
|
|
||||||
# system_name -> system_id or 0
|
|
||||||
def system_id(system_name):
|
|
||||||
return this.system_ids.get(system_name, [0, False])[0]
|
|
||||||
|
|
||||||
# system_name -> is_populated
|
|
||||||
def system_populated(system_name):
|
|
||||||
return this.system_ids.get(system_name, [0, False])[1]
|
|
||||||
|
|
||||||
# (system_name, station_name) -> station_id or 0
|
|
||||||
def station_id(system_name, station_name):
|
|
||||||
return this.station_ids.get((system_id(system_name), station_name), 0)
|
|
||||||
|
|
||||||
|
|
||||||
def plugin_start3(plugin_dir):
|
def plugin_start3(plugin_dir):
|
||||||
return 'eddb'
|
return 'eddb'
|
||||||
|
|
||||||
def plugin_app(parent):
|
def plugin_app(parent):
|
||||||
this.system_link = parent.children['system'] # system label in main window
|
this.system_link = parent.children['system'] # system label in main window
|
||||||
|
this.system_address = None
|
||||||
|
this.station_marketid = None # Frontier MarketID
|
||||||
this.station_link = parent.children['station'] # station label in main window
|
this.station_link = parent.children['station'] # station label in main window
|
||||||
this.station_link.configure(popup_copy = lambda x: x != STATION_UNDOCKED)
|
this.station_link.configure(popup_copy = lambda x: x != STATION_UNDOCKED)
|
||||||
|
|
||||||
def prefs_changed(cmdr, is_beta):
|
def prefs_changed(cmdr, is_beta):
|
||||||
if config.get('system_provider') == 'eddb':
|
if config.get('system_provider') == 'eddb':
|
||||||
this.system_link['url'] = system_url(system_link['text']) # Override standard URL function
|
this.system_link['url'] = system_url(this.system_address) # Override standard URL function
|
||||||
|
|
||||||
|
|
||||||
def journal_entry(cmdr, is_beta, system, station, entry, state):
|
def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||||
if config.get('system_provider') == 'eddb':
|
if config.get('system_provider') == 'eddb':
|
||||||
this.system_link['url'] = system_url(system) # Override standard URL function
|
this.system_address = entry.get('SystemAddress') or this.system_address
|
||||||
this.station_link['text'] = station or (system_populated(system) and STATION_UNDOCKED or '')
|
this.system_link['url'] = system_url(this.system_address) # Override standard URL function
|
||||||
|
|
||||||
|
if config.get('station_provider') == 'eddb':
|
||||||
|
if entry['event'] in ['StartUp', 'Location', 'FSDJump', 'CarrierJump']:
|
||||||
|
this.system_population = entry.get('Population')
|
||||||
|
|
||||||
|
if entry['event'] in ['StartUp', 'Location', 'Docked', 'CarrierJump']:
|
||||||
|
this.station_marketid = entry.get('MarketID')
|
||||||
|
elif entry['event'] in ['Undocked']:
|
||||||
|
this.station_marketid = None
|
||||||
|
|
||||||
|
this.station_link['text'] = station or (this.system_population and this.system_population > 0 and STATION_UNDOCKED or '')
|
||||||
this.station_link.update_idletasks()
|
this.station_link.update_idletasks()
|
||||||
|
|
||||||
|
|
||||||
def cmdr_data(data, is_beta):
|
def cmdr_data(data, is_beta):
|
||||||
if config.get('system_provider') == 'eddb':
|
if config.get('system_provider') == 'eddb':
|
||||||
this.system_link['url'] = system_url(data['lastSystem']['name']) # Override standard URL function
|
this.system_address = data['lastSystem']['id'] or this.system_address
|
||||||
this.station_link['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (system_populated(data['lastSystem']['name']) and STATION_UNDOCKED or '')
|
this.system_link['url'] = system_url(this.system_address) # Override standard URL function
|
||||||
|
|
||||||
|
if config.get('station_provider') == 'eddb':
|
||||||
|
this.station_marketid = data['commander']['docked'] and data['lastStarport']['id']
|
||||||
|
this.station_link['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (data['lastStarport']['name'] and data['lastStarport']['name'] != "" and STATION_UNDOCKED or '')
|
||||||
this.station_link.update_idletasks()
|
this.station_link.update_idletasks()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user