From 49cc2e1f2a4609df46297ae46f1605cd024ac9b7 Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Tue, 19 Jan 2016 19:46:34 +0000 Subject: [PATCH] Don't send the Training system to EDSM. Fixes #81. --- edsm.py | 17 ++++++++++++++--- monitor.py | 4 ++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/edsm.py b/edsm.py index ca356f9a..a9aaebaf 100644 --- a/edsm.py +++ b/edsm.py @@ -15,6 +15,7 @@ if __debug__: class EDSM: _TIMEOUT = 10 + FAKE = ['CQC', 'Training'] # Fake systems that shouldn't be sent to EDSM def __init__(self): self.result = { 'img': None, 'url': None, 'done': True } @@ -28,12 +29,17 @@ class EDSM: # Just set link without doing a lookup def link(self, system_name): self.cancel_lookup() - self.result = { 'img': '', 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True, 'uncharted': False } + if system_name in self.FAKE: + self.result = { 'img': '', 'url': None, 'done': True, 'uncharted': False } + else: + self.result = { 'img': '', 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True, 'uncharted': False } def lookup(self, system_name, known=0): self.cancel_lookup() - if known or system_name in self.syscache: + if system_name in self.FAKE: + self.result = { 'img': '', 'url': None, 'done': True, 'uncharted': False } + elif known or system_name in self.syscache: self.result = { 'img': EDSM._IMG_KNOWN, 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True, 'uncharted': False } else: self.result = { 'img': EDSM._IMG_ERROR, 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True, 'uncharted': False } @@ -56,7 +62,9 @@ class EDSM: def start_lookup(self, system_name, known=0): self.cancel_lookup() - if known or system_name in self.syscache: # Cache URLs of systems with known coordinates + if system_name in self.FAKE: + self.result = { 'img': '', 'url': None, 'done': True, 'uncharted': False } + elif known or system_name in self.syscache: # Cache URLs of systems with known coordinates self.result = { 'img': EDSM._IMG_KNOWN, 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True, 'uncharted': False } else: self.result = { 'img': '', 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': False, 'uncharted': False } @@ -107,6 +115,9 @@ def writelog(timestamp, system, edsmlookupfn): # Look up the system before adding it to the log, since adding it to the log has the side-effect of creating it 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')), 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) r.raise_for_status() reply = r.json() diff --git a/monitor.py b/monitor.py index a80c44a6..f70e4002 100644 --- a/monitor.py +++ b/monitor.py @@ -223,10 +223,10 @@ class EDLogs(FileSystemEventHandler): cqc = True elif 'Left a playlist lobby' in match.group(1) or 'Destroying playlist lobby' in match.group(1): cqc = False - elif not cqc: + else: match = regexp.match(line) if match: - system, visited = match.group(2), match.group(1) + system, visited = cqc and 'CQC' or match.group(2), match.group(1) if system: self._restart_required = False # clearly logging is working