1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

Get system coordinates from 1.6/2.1 netlog

This commit is contained in:
Jonathan Harris 2016-06-03 23:34:30 +01:00
parent fb7b0401fa
commit c5e50240b0
No known key found for this signature in database
GPG Key ID: D997C6582365A060
20 changed files with 40 additions and 62 deletions

View File

@ -9,7 +9,6 @@ from os.path import expanduser, isdir, join
import re
import requests
from time import time, localtime, strftime
import webbrowser
import Tkinter as tk
import ttk
@ -512,7 +511,7 @@ class AppWindow:
except:
pass
def system_change(self, timestamp, system):
def system_change(self, timestamp, system, coordinates):
if self.system['text'] != system:
self.system['text'] = system
@ -520,7 +519,7 @@ class AppWindow:
self.system['image'] = ''
self.station['text'] = EDDB.system(system) and self.STATION_UNDOCKED or ''
plug.notify_system_changed(timestamp, system)
plug.notify_system_changed(timestamp, system, coordinates)
if config.getint('output') & config.OUT_LOG_FILE:
flightlog.writelog(timestamp, system)
@ -528,7 +527,7 @@ class AppWindow:
try:
self.status['text'] = _('Sending data to EDSM...')
self.w.update_idletasks()
edsm.writelog(timestamp, system, lambda:self.edsm.lookup(system, EDDB.system(system))) # Do EDSM lookup during EDSM export
edsm.writelog(timestamp, system, lambda:self.edsm.lookup(system, EDDB.system(system)), coordinates) # Do EDSM lookup during EDSM export
self.status['text'] = strftime(_('Last updated at {HH}:{MM}:{SS}').format(HH='%H', MM='%M', SS='%S').encode('utf-8'), localtime(timestamp)).decode('utf-8')
except Exception as e:
if __debug__: print_exc()
@ -544,8 +543,6 @@ class AppWindow:
result = self.edsm.result
if result['done']:
self.system['image'] = result['img']
if result['uncharted'] and config.getint('edsm_autoopen'):
webbrowser.open(result['url'])
else:
self.w.after(int(EDSM_POLL * 1000), self.edsmpoll)

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Automaticky vytvořit záznam při vstoupení do systému";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Automaticky otevřít EDSM stránku nezmapovaných systémů";
/* Cmdr stats. [stats.py] */
"Balance" = "Zůstatek";

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Automatisch Logbucheintrag bei Systemeintritt anlegen";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Automatisch die EDSM Seite unerforschter Systeme öffnen";
/* Cmdr stats. [stats.py] */
"Balance" = "Kontostand";

View File

@ -28,9 +28,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Automatically make a log entry on entering a system";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Automatically open uncharted systems EDSM pages";
/* Cmdr stats. [stats.py] */
"Balance" = "Balance";

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Crear automáticamente una entrada en el registro al entrar en un sistema";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Abrir automáticamente sistemas no cartografiados en EDSM";
/* Cmdr stats. [stats.py] */
"Balance" = "Saldo";

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Ajouter automatiquement une entrée au journal en entrant dans un système";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Ouvrir automatiquement les pages EDSM des systèmes inexplorés";
/* Cmdr stats. [stats.py] */
"Balance" = "Solde";

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Inserisce automaticamente una log entry entrando in un sistema";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Apre automaticamente una pagina su EDSM dei sistemi non esplorati";
/* Cmdr stats. [stats.py] */
"Balance" = "Saldo";

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "別の星系に移動したら自動的にフライトログを記録する";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "EDSMに座標が登録されていない星系のページを自動的に開く";
/* Cmdr stats. [stats.py] */
"Balance" = "Balance";

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Automātiski veikt ierakstu ierodoties sistēmā";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Automātiski atvērt neatklāto sistēmu EDSM lapas";
/* Cmdr stats. [stats.py] */
"Balance" = "Bilance";

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Automatisch een log regel aanmaken bij het binnengaan van een stelsel";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Automatisch openen van nog niet in kaart gebrachte systemen op EDSM website";
/* Cmdr stats. [stats.py] */
"Balance" = "Balans";

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Stwórz automatycznie wpis w logu po wejściu do systemu";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Automatycznie otwieraj nie skatalogowane systemy w EDSM";
/* Cmdr stats. [stats.py] */
"Balance" = "Saldo";

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Автоматически заносить в журнал полета каждую посещённую систему";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Автоматически открывать EDSM для неисследованных систем";
/* Cmdr stats. [stats.py] */
"Balance" = "Баланс";

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Shrani podatke v dnevnik leta, ko prispeš v sistem";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Automatically open uncharted systems EDSM pages";
/* Cmdr stats. [stats.py] */
"Balance" = "Ravnotežje";

View File

@ -31,9 +31,6 @@
/* Output setting. [prefs.py] */
"Automatically make a log entry on entering a system" = "Автоматично робити запис у журналі на вході в систему";
/* [prefs.py] */
"Automatically open uncharted systems EDSM pages" = "Автоматично відкривати сторінки EDSM, для незвіданих систем";
/* Cmdr stats. [stats.py] */
"Balance" = "Баланс";

View File

@ -73,7 +73,7 @@ Your events all get called on the main tkinter loop so be sure not to block for
This gets called when EDMC uses the netlog to notice that you have arrived at a new star system.
```
def system_changed(timestamp, system):
def system_changed(timestamp, system, coordinates):
"""
We arrived at a new system!
"""

14
edsm.py
View File

@ -109,7 +109,7 @@ def export(data, edsmlookupfn):
writelog(querytime, data['lastSystem']['name'], edsmlookupfn)
def writelog(timestamp, system, edsmlookupfn):
def writelog(timestamp, system, edsmlookupfn, coordinates=None):
try:
# Look up the system before adding it to the log, since adding it to the log has the side-effect of creating it
@ -118,7 +118,17 @@ def writelog(timestamp, system, edsmlookupfn):
if system in EDSM.FAKE:
return
r = requests.get('http://www.edsm.net/api-logs-v1/set-log?commanderName=%s&apiKey=%s&systemName=%s&dateVisited=%s&fromSoftware=%s&fromSoftwareVersion=%s' % (urllib.quote(config.get('edsm_cmdrname').encode('utf-8')), urllib.quote(config.get('edsm_apikey')), urllib.quote(system), urllib.quote(time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(timestamp))), urllib.quote(applongname), urllib.quote(appversion)), timeout=EDSM._TIMEOUT)
url = 'http://www.edsm.net/api-logs-v1/set-log?commanderName=%s&apiKey=%s&systemName=%s&dateVisited=%s&fromSoftware=%s&fromSoftwareVersion=%s' % (
urllib.quote(config.get('edsm_cmdrname').encode('utf-8')),
urllib.quote(config.get('edsm_apikey')),
urllib.quote(system),
urllib.quote(time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(timestamp))),
urllib.quote(applongname),
urllib.quote(appversion)
)
if coordinates:
url += '&x=%.3f&y=%.3f&z=%.3f' % coordinates
r = requests.get(url, timeout=EDSM._TIMEOUT)
r.raise_for_status()
reply = r.json()
(msgnum, msg) = reply['msgnum'], reply['msg']

View File

@ -193,9 +193,14 @@ class EDLogs(FileSystemEventHandler):
self.logfile = event.src_path
def worker(self):
# e.g. "{18:11:44} System:22(Gamma Doradus) Body:3 Pos:(3.69928e+07,1.13173e+09,-1.75892e+08) \r\n" or "... NormalFlight\r\n" or "... Supercruise\r\n"
# e.g.:
# "{18:00:41} System:"Shinrarta Dezhra" StarPos:(55.719,17.594,27.156)ly NormalFlight\r\n"
# or with verboseLogging:
# "{17:20:18} System:"Shinrarta Dezhra" StarPos:(55.719,17.594,27.156)ly Body:69 RelPos:(0.334918,1.20754,1.23625)km NormalFlight\r\n"
# or:
# "... Supercruise\r\n"
# Note that system name may contain parantheses, e.g. "Pipe (stem) Sector PI-T c3-5".
regexp = re.compile(r'\{(.+)\} System:\d+\((.+)\) Body:(\d+) .* (\S*)') # (localtime, system, body, context)
regexp = re.compile(r'\{(.+)\} System:"(.+)" StarPos:\((.+),(.+),(.+)\)ly.* (\S+)') # (localtime, system, x, y, z, context)
# Seek to the end of the latest log file
logfile = self.logfile
@ -215,13 +220,16 @@ class EDLogs(FileSystemEventHandler):
loghandle = open(logfile, 'rt')
if logfile:
system = visited = None
system = visited = coordinates = None
loghandle.seek(0, 1) # reset EOF flag
for line in loghandle:
match = regexp.match(line)
if match:
system, visited = match.group(4) == 'ProvingGround' and 'CQC' or match.group(2), match.group(1)
(visited, system, x, y, z, context) = match.groups()
if system == 'ProvingGround':
system = 'CQC'
coordinates = (float(x), float(y), float(z))
if system:
self._restart_required = False # clearly logging is working
@ -233,7 +241,7 @@ class EDLogs(FileSystemEventHandler):
now = localtime(time()-12*60*60) # yesterday
time_struct = datetime(now.tm_year, now.tm_mon, now.tm_mday, visited_struct.tm_hour, visited_struct.tm_min, visited_struct.tm_sec).timetuple() # still local time
# Tk on Windows doesn't like to be called outside of an event handler, so generate an event
self.last_event = (mktime(time_struct), system)
self.last_event = (mktime(time_struct), system, coordinates)
self.root.event_generate('<<MonitorJump>>', when="tail")
sleep(10) # New system gets posted to log file before hyperspace ends, so don't need to poll too often

View File

@ -87,7 +87,7 @@ def get_plugin_pref(plugname, parent):
return None
def notify_system_changed(timestamp, system):
def notify_system_changed(timestamp, system, coordinates):
"""
Send notification data to each plugin when we arrive at a new system.
:param timestamp:
@ -98,7 +98,10 @@ def notify_system_changed(timestamp, system):
system_changed = _get_plugin_func(plugname, "system_changed")
if system_changed:
try:
system_changed(timestamp, system)
if system_changed.func_code.co_argcount == 2:
system_changed(timestamp, system)
else:
system_changed(timestamp, system, coordinates)
except Exception as plugerr:
print plugerr

View File

@ -45,14 +45,18 @@ def plugin_app(parent):
return plugin_app.status
def system_changed(timestamp, system):
def system_changed(timestamp, system, coordinates):
"""
Arrived in a new System
:param timestamp: when we arrived
:param system: the name of the system
:param coordinates: tuple of (x,y,z) ly relative to Sol, or None if unknown
:return:
"""
sys.stderr.write("Arrived at {}\n".format(system))
if coordinates:
sys.stderr.write("Arrived at {} ({},{},{})\n".format(system, *coordinates))
else:
sys.stderr.write("Arrived at {}\n".format(system))
def cmdr_data(data):

View File

@ -159,9 +159,6 @@ class PreferencesDialog(tk.Toplevel):
ttk.Separator(edsmframe, orient=tk.HORIZONTAL).grid(columnspan=2, padx=PADX, pady=PADY, sticky=tk.EW)
self.out_log_edsm = tk.IntVar(value = (output & config.OUT_LOG_EDSM) and 1)
nb.Checkbutton(edsmframe, text=_('Send flight log to Elite Dangerous Star Map'), variable=self.out_log_edsm, command=self.outvarchanged).grid(columnspan=2, padx=BUTTONX, sticky=tk.W)
self.edsm_autoopen = tk.BooleanVar(value = config.getint('edsm_autoopen'))
self.edsm_autoopen_button = nb.Checkbutton(edsmframe, text=_(u"Automatically open uncharted systems EDSM pages"), variable=self.edsm_autoopen)
self.edsm_autoopen_button.grid(columnspan=2, padx=BUTTONX, sticky=tk.W)
self.edsm_log_auto_button = nb.Checkbutton(edsmframe, text=_('Automatically make a log entry on entering a system'), variable=self.out_log_auto, command=self.outvarchanged) # Output setting
self.edsm_log_auto_button.grid(columnspan=2, padx=BUTTONX, sticky=tk.W)
self.edsm_log_auto_text = nb.Label(edsmframe, foreground='firebrick')
@ -294,7 +291,6 @@ class PreferencesDialog(tk.Toplevel):
self.outdir['state'] = local and 'readonly' or tk.DISABLED
edsm_state = self.out_log_edsm.get() and tk.NORMAL or tk.DISABLED
self.edsm_autoopen_button['state'] = edsm_state
self.edsm_label['state'] = edsm_state
self.edsm_cmdr_label['state'] = edsm_state
self.edsm_apikey_label['state'] = edsm_state
@ -441,7 +437,6 @@ class PreferencesDialog(tk.Toplevel):
(self.out_log_auto.get() and config.OUT_LOG_AUTO))
config.set('outdir', self.outdir.get().startswith('~') and join(config.home, self.outdir.get()[2:]) or self.outdir.get())
config.set('edsm_autoopen', self.edsm_autoopen.get())
config.set('edsm_cmdrname', self.edsm_cmdr.get().strip())
config.set('edsm_apikey', self.edsm_apikey.get().strip())