From 9564d8ab4fda060df0779a42f1a9fddbf40a186a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 28 Sep 2020 12:00:28 +0100 Subject: [PATCH 1/5] EDDN: Allow sending of empty market data for updating FCs. --- plugins/eddn.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 5e7f27fe..7809cdd9 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -147,6 +147,13 @@ Headers\t{r.headers} Content:\n{r.text} Msg:\n{msg}''') + # Check if EDDN is still objecting to an empty commodities list + if r.status_code == 400 \ + and msg['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/3' \ + and this.commodities == [] \ + and r.text == "FAIL: []": + logger.trace("EDDN is still objecting to empty commodities data") + r.raise_for_status() def sendreplay(self) -> None: @@ -238,7 +245,13 @@ Msg:\n{msg}''') commodities.sort(key=lambda c: c['name']) - if commodities and this.commodities != commodities: # Don't send empty commodities list - schema won't allow it + # This used to have a check `commodities and ` at the start so as to + # not send an empty commodities list, as the EDDN Schema doesn't allow + # it (as of 2020-09-28). + # BUT, Fleet Carriers can go from having buy/sell orders to having + # none and that really does need to be recorded over EDDN so that, e.g. + # EDDB can update in a timely manner. + if this.commodities != commodities: message: OrderedDictT[str, Any] = OrderedDict([ ('timestamp', data['timestamp']), ('systemName', data['lastSystem']['name']), From ca4214fff8871b01c82a4c7fd93be8f2e94b716f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 28 Sep 2020 12:26:09 +0100 Subject: [PATCH 2/5] EDDN: Catch and log 'we tried to send empty market'. Very tight check on this to be sure we don't ignore other errors. r.status_code == 400 # Not a different code $schemaRef == commodities The message had empty commodities list r.text == expected return from EDDN Gateway --- plugins/eddn.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 7809cdd9..e7e576ad 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -140,19 +140,22 @@ class EDDN: r = self.session.post(self.UPLOAD, data=json.dumps(to_send), timeout=self.TIMEOUT) if r.status_code != requests.codes.ok: + + # Check if EDDN is still objecting to an empty commodities list + if r.status_code == 400 \ + and msg['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/3' \ + and msg['message']['commodities'] == [] \ + and r.text == "FAIL: []": + logger.trace("EDDN is still objecting to empty commodities data") + return # We want to silence warnings otherwise + logger.debug(f'''Status from POST wasn't OK: Status\t{r.status_code} URL\t{r.url} Headers\t{r.headers} Content:\n{r.text} -Msg:\n{msg}''') - - # Check if EDDN is still objecting to an empty commodities list - if r.status_code == 400 \ - and msg['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/3' \ - and this.commodities == [] \ - and r.text == "FAIL: []": - logger.trace("EDDN is still objecting to empty commodities data") +Msg:\n{msg}''' + ) r.raise_for_status() From e908cce242cc9a8e617e1ae0bdcae2aa39232e68 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 28 Sep 2020 12:41:44 +0100 Subject: [PATCH 3/5] Change the multi-line conditional to using () not \\n --- plugins/eddn.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index e7e576ad..238a5e18 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -142,10 +142,10 @@ class EDDN: if r.status_code != requests.codes.ok: # Check if EDDN is still objecting to an empty commodities list - if r.status_code == 400 \ - and msg['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/3' \ - and msg['message']['commodities'] == [] \ - and r.text == "FAIL: []": + if (r.status_code == 400 + and msg['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/3' + and msg['message']['commodities'] == [] + and r.text == "FAIL: []"): logger.trace("EDDN is still objecting to empty commodities data") return # We want to silence warnings otherwise From dea7b3660aec5349468c8a83d59326a06aab03d3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 28 Sep 2020 12:48:53 +0100 Subject: [PATCH 4/5] Minor formatting cleanups --- plugins/eddn.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 238a5e18..d3df791a 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -142,20 +142,23 @@ class EDDN: if r.status_code != requests.codes.ok: # Check if EDDN is still objecting to an empty commodities list - if (r.status_code == 400 + if ( + r.status_code == 400 and msg['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/3' and msg['message']['commodities'] == [] - and r.text == "FAIL: []"): + and r.text == "FAIL: []" + ): logger.trace("EDDN is still objecting to empty commodities data") return # We want to silence warnings otherwise - logger.debug(f'''Status from POST wasn't OK: + logger.debug( + f'''Status from POST wasn't OK: Status\t{r.status_code} URL\t{r.url} Headers\t{r.headers} Content:\n{r.text} Msg:\n{msg}''' - ) + ) r.raise_for_status() From abc1507aa0ba42104619004455bcdbc7416ce0af Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 28 Sep 2020 13:02:10 +0100 Subject: [PATCH 5/5] Also allow sending empty commodities from Market.json --- plugins/eddn.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index d3df791a..29de4910 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -409,7 +409,13 @@ Msg:\n{msg}''' ('demandBracket', commodity['DemandBracket']), ]) for commodity in items), key=lambda c: c['name']) - if commodities and this.commodities != commodities: # Don't send empty commodities list - schema won't allow it + # This used to have a check `commodities and ` at the start so as to + # not send an empty commodities list, as the EDDN Schema doesn't allow + # it (as of 2020-09-28). + # BUT, Fleet Carriers can go from having buy/sell orders to having + # none and that really does need to be recorded over EDDN so that, e.g. + # EDDB can update in a timely manner. + if this.commodities != commodities: self.send(cmdr, { '$schemaRef': f'https://eddn.edcd.io/schemas/commodity/3{"/test" if is_beta else ""}', 'message': OrderedDict([ @@ -722,6 +728,7 @@ def journal_entry( # noqa: C901 elif (config.getint('output') & config.OUT_MKT_EDDN and not state['Captain'] and entry['event'] in ('Market', 'Outfitting', 'Shipyard')): + # Market.json, Outfitting.json or Shipyard.json to process try: if this.marketId != entry['MarketID']: