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

Send blackmarket messages to EDDN

This commit is contained in:
Jonathan Harris 2016-09-15 17:03:42 +01:00
parent 4d3fe1808c
commit 6f4a3b37a3
2 changed files with 41 additions and 17 deletions

View File

@ -3,6 +3,7 @@
import sys
from sys import platform
from collections import OrderedDict
from functools import partial
import json
from os import mkdir
@ -526,13 +527,11 @@ class AppWindow:
self.w.after(int(SERVER_RETRY * 1000), self.getandsend)
# Send interesting events to EDDN
if (config.getint('output') & config.OUT_SYS_EDDN and monitor.cmdr and
(entry['event'] == 'FSDJump' and system_changed or
entry['event'] == 'Docked' and station_changed or
entry['event'] == 'Scan' and monitor.system)):
try:
self.status['text'] = _('Sending data to EDDN...')
try:
if (config.getint('output') & config.OUT_SYS_EDDN and monitor.cmdr and
(entry['event'] == 'FSDJump' and system_changed or
entry['event'] == 'Docked' and station_changed or
entry['event'] == 'Scan' and monitor.system)):
# strip out properties disallowed by the schema
for thing in ['CockpitBreach', 'BoostUsed', 'FuelLevel', 'FuelUsed', 'JumpDist']:
entry.pop(thing, None)
@ -544,20 +543,38 @@ class AppWindow:
if 'StarSystem' not in entry:
entry['StarSystem'] = monitor.system
self.status['text'] = _('Sending data to EDDN...')
eddn.export_journal_entry(monitor.cmdr, monitor.is_beta, entry)
self.status['text'] = ''
except requests.exceptions.RequestException as e:
if __debug__: print_exc()
self.status['text'] = _("Error: Can't connect to EDDN")
if not config.getint('hotkey_mute'):
hotkeymgr.play_bad()
elif (config.getint('output') & config.OUT_MKT_EDDN and monitor.cmdr and
entry['event'] == 'MarketSell' and entry.get('BlackMarket')):
# Construct blackmarket message
msg = OrderedDict([
('systemName', monitor.system),
('stationName', monitor.station),
('timestamp', entry['timestamp']),
('name', entry['Type']),
('sellPrice', entry['SellPrice']),
('prohibited' , entry.get('IllegalGoods', False)),
])
self.status['text'] = _('Sending data to EDDN...')
eddn.export_blackmarket(monitor.cmdr, monitor.is_beta, msg)
self.status['text'] = ''
except requests.exceptions.RequestException as e:
if __debug__: print_exc()
self.status['text'] = _("Error: Can't connect to EDDN")
if not config.getint('hotkey_mute'):
hotkeymgr.play_bad()
except Exception as e:
if __debug__: print_exc()
self.status['text'] = unicode(e)
if not config.getint('hotkey_mute'):
hotkeymgr.play_bad()
except Exception as e:
if __debug__: print_exc()
self.status['text'] = unicode(e)
if not config.getint('hotkey_mute'):
hotkeymgr.play_bad()
def edsmpoll(self):
result = self.edsm.result

View File

@ -151,5 +151,12 @@ class _EDDN:
'message' : entry
})
def export_blackmarket(self, cmdr, is_beta, msg):
self.send(cmdr, {
'$schemaRef' : 'http://schemas.elite-markets.net/eddn/blackmarket/1' + (is_beta and '/test' or ''),
'message' : msg
})
# singleton
eddn = _EDDN()