mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-02 16:41:04 +03:00
Merge pull request #152 from AnthorNet/master
Send Balance/Loan/ShipID to EDSM
This commit is contained in:
commit
bfd1954afa
@ -499,18 +499,45 @@ 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 balance/loan 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 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
|
||||
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 ranks 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
|
||||
@ -527,7 +554,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'] = ''
|
||||
|
49
edsm.py
49
edsm.py
@ -167,3 +167,52 @@ 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))
|
||||
|
||||
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))
|
||||
|
@ -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,10 +220,14 @@ 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 ['ShipyardSwap']:
|
||||
self.shipid = entry['ShipID']
|
||||
elif entry['event'] in ['Undocked']:
|
||||
self.station = None
|
||||
elif entry['event'] in ['Location', 'FSDJump', 'Docked']:
|
||||
|
Loading…
x
Reference in New Issue
Block a user