From 31af8be0483a7adf84bf996309745001048b361f Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Wed, 26 Oct 2016 14:05:11 +0200 Subject: [PATCH 1/7] Add shipId / Credits from LoadGame event --- monitor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/monitor.py b/monitor.py index affade34..22d305a8 100644 --- a/monitor.py +++ b/monitor.py @@ -77,10 +77,12 @@ class EDLogs(FileSystemEventHandler): self.is_beta = False self.mode = None self.cmdr = None + self.shipId = None self.system = None self.station = None self.coordinates = None self.ranks = None + self.credits = None def set_callback(self, name, callback): if name in self.callbacks: @@ -218,8 +220,10 @@ class EDLogs(FileSystemEventHandler): self.ranks = None elif entry['event'] == 'LoadGame': self.cmdr = entry['Commander'] + self.shipId = entry['ShipID'] self.mode = entry.get('GameMode') # 'Open', 'Solo', 'Group', or None for CQC self.ranks = { "Combat": None, "Trade": None, "Explore": None, "Empire": None, "Federation": None, "CQC": None } + self.credits = { "balance": entry['Credits'], "loan": entry['Loan'] } elif entry['event'] == 'NewCommander': self.cmdr = entry['Name'] elif entry['event'] in ['Undocked']: From 43ba88fe8caf542fb62b35bc8b4c057233c3021d Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Wed, 26 Oct 2016 14:08:37 +0200 Subject: [PATCH 2/7] Add setcredits method --- edsm.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/edsm.py b/edsm.py index ede7087a..80154457 100644 --- a/edsm.py +++ b/edsm.py @@ -167,3 +167,28 @@ class EDSM: if msgnum // 100 not in (1,4): raise Exception(_('Error: EDSM {MSG}').format(MSG=msg)) + + def setcredits(self, credits): + if not credits: + return + + try: + url = 'https://www.edsm.net/api-commander-v1/set-credits?commanderName=%s&apiKey=%s&fromSoftware=%s&fromSoftwareVersion=%s' % ( + urllib2.quote(config.get('edsm_cmdrname').encode('utf-8')), + urllib2.quote(config.get('edsm_apikey')), + urllib2.quote(applongname), + urllib2.quote(appversion) + ) + + url += '&%s=%s' % ('balance', urllib2.quote('%d;%d' % credits['balance'])) + url += '&%s=%s' % ('loan', urllib2.quote('%d;%d' % credits['loan'])) + + r = self.opener.open(url, timeout=EDSM._TIMEOUT) + reply = json.loads(r.read()) + (msgnum, msg) = reply['msgnum'], reply['msg'] + except: + if __debug__: print_exc() + raise Exception(_("Error: Can't connect to EDSM")) + + if msgnum // 100 not in (1,4): + raise Exception(_('Error: EDSM {MSG}').format(MSG=msg)) From 99700686c60280e084a377e88ad50fb26c315f0e Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Wed, 26 Oct 2016 14:13:30 +0200 Subject: [PATCH 3/7] Send credits on LoadGame --- EDMarketConnector.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 25845cb1..943b8690 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -499,18 +499,32 @@ class AppWindow: if system_changed or station_changed: self.status['text'] = '' - if config.getint('output') & config.OUT_SYS_EDSM and not monitor.is_beta and monitor.ranks and (not entry or entry['event'] in ['Progress', 'Promotion']): + if config.getint('output') & config.OUT_SYS_EDSM and not monitor.is_beta: + # Send credits to EDSM on startup + if monitor.credits and (not entry or entry['event'] == 'LoadGame'): + try: + self.status['text'] = _('Sending data to EDSM...') + self.w.update_idletasks() + self.edsm.setcredits(monitor.credits) + self.status['text'] = '' + except Exception as e: + if __debug__: print_exc() + self.status['text'] = unicode(e) + if not config.getint('hotkey_mute'): + hotkeymgr.play_bad() + # Send rank info to EDSM on startup or change - try: - self.status['text'] = _('Sending data to EDSM...') - self.w.update_idletasks() - self.edsm.setranks(monitor.ranks) - self.status['text'] = '' - except Exception as e: - if __debug__: print_exc() - self.status['text'] = unicode(e) - if not config.getint('hotkey_mute'): - hotkeymgr.play_bad() + if monitor.ranks and (not entry or entry['event'] in ['Progress', 'Promotion']): + try: + self.status['text'] = _('Sending data to EDSM...') + self.w.update_idletasks() + self.edsm.setranks(monitor.ranks) + self.status['text'] = '' + except Exception as e: + if __debug__: print_exc() + self.status['text'] = unicode(e) + if not config.getint('hotkey_mute'): + hotkeymgr.play_bad() if not entry or not monitor.mode: return # Fake event or in CQC From 5a08907060acffdfda5204b71519ab4b11410510 Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Wed, 26 Oct 2016 14:15:28 +0200 Subject: [PATCH 4/7] Better status to EDSM --- EDMarketConnector.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 943b8690..d78dd0ab 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -503,7 +503,7 @@ class AppWindow: # Send credits to EDSM on startup if monitor.credits and (not entry or entry['event'] == 'LoadGame'): try: - self.status['text'] = _('Sending data to EDSM...') + self.status['text'] = _('Sending balance/loan to EDSM...') self.w.update_idletasks() self.edsm.setcredits(monitor.credits) self.status['text'] = '' @@ -516,7 +516,7 @@ class AppWindow: # Send rank info to EDSM on startup or change if monitor.ranks and (not entry or entry['event'] in ['Progress', 'Promotion']): try: - self.status['text'] = _('Sending data to EDSM...') + self.status['text'] = _('Sending ranks to EDSM...') self.w.update_idletasks() self.edsm.setranks(monitor.ranks) self.status['text'] = '' @@ -541,7 +541,7 @@ class AppWindow: # Update EDSM if we have coordinates - i.e. Location or FSDJump events if config.getint('output') & config.OUT_SYS_EDSM and monitor.coordinates: try: - self.status['text'] = _('Sending data to EDSM...') + self.status['text'] = _('Sending flight log to EDSM...') self.w.update_idletasks() self.edsm.writelog(timestamp, monitor.system, monitor.coordinates) self.status['text'] = '' From 65ecd7c261e466814696aa443cc315b8e88392cd Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Wed, 26 Oct 2016 14:58:35 +0200 Subject: [PATCH 5/7] Add shipid method --- edsm.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/edsm.py b/edsm.py index 80154457..311cc305 100644 --- a/edsm.py +++ b/edsm.py @@ -192,3 +192,27 @@ class EDSM: if msgnum // 100 not in (1,4): raise Exception(_('Error: EDSM {MSG}').format(MSG=msg)) + + def setshipid(self, shipid): + if not shipid: + return + + try: + url = 'https://www.edsm.net/api-commander-v1/set-ship-id?commanderName=%s&apiKey=%s&fromSoftware=%s&fromSoftwareVersion=%s' % ( + urllib2.quote(config.get('edsm_cmdrname').encode('utf-8')), + urllib2.quote(config.get('edsm_apikey')), + urllib2.quote(applongname), + urllib2.quote(appversion) + ) + + url += '&%s=%s' % ('shipId', urllib2.quote('%d;%d' % shipid)) + + r = self.opener.open(url, timeout=EDSM._TIMEOUT) + reply = json.loads(r.read()) + (msgnum, msg) = reply['msgnum'], reply['msg'] + except: + if __debug__: print_exc() + raise Exception(_("Error: Can't connect to EDSM")) + + if msgnum // 100 not in (1,4): + raise Exception(_('Error: EDSM {MSG}').format(MSG=msg)) From d1f271b3aec707d0881e4264cc04c5a4719eb3be Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Wed, 26 Oct 2016 15:05:40 +0200 Subject: [PATCH 6/7] Add shipid to ShipyardSwap Event --- monitor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index 22d305a8..1be69a13 100644 --- a/monitor.py +++ b/monitor.py @@ -77,7 +77,7 @@ class EDLogs(FileSystemEventHandler): self.is_beta = False self.mode = None self.cmdr = None - self.shipId = None + self.shipid = None self.system = None self.station = None self.coordinates = None @@ -220,12 +220,14 @@ class EDLogs(FileSystemEventHandler): self.ranks = None elif entry['event'] == 'LoadGame': self.cmdr = entry['Commander'] - self.shipId = entry['ShipID'] + self.shipid = entry['ShipID'] self.mode = entry.get('GameMode') # 'Open', 'Solo', 'Group', or None for CQC self.ranks = { "Combat": None, "Trade": None, "Explore": None, "Empire": None, "Federation": None, "CQC": None } self.credits = { "balance": entry['Credits'], "loan": entry['Loan'] } elif entry['event'] == 'NewCommander': self.cmdr = entry['Name'] + elif entry['event'] in ['ShipyardSwap']: + self.shipid = entry['ShipID'] elif entry['event'] in ['Undocked']: self.station = None elif entry['event'] in ['Location', 'FSDJump', 'Docked']: From 1fe9758c5255562946bc41d928ccfee9a340ddfe Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Wed, 26 Oct 2016 15:05:53 +0200 Subject: [PATCH 7/7] Send ship id on LoadGame and ShipyardSwap events --- EDMarketConnector.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index d78dd0ab..be0167b5 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -513,6 +513,19 @@ class AppWindow: if not config.getint('hotkey_mute'): hotkeymgr.play_bad() + # Send shipid to EDSM on startup or change + if monitor.shipid and (not entry or entry['event'] in ['LoadGame', 'ShipyardSwap']): + try: + self.status['text'] = _('Sending shipId to EDSM...') + self.w.update_idletasks() + self.edsm.setshipid(monitor.shipid) + self.status['text'] = '' + except Exception as e: + if __debug__: print_exc() + self.status['text'] = unicode(e) + if not config.getint('hotkey_mute'): + hotkeymgr.play_bad() + # Send rank info to EDSM on startup or change if monitor.ranks and (not entry or entry['event'] in ['Progress', 'Promotion']): try: