mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-17 17:42:20 +03:00
Move recording and fixup of commodity data to top-level.
This commit is contained in:
parent
437997e963
commit
5ca37ed3bd
@ -3,6 +3,7 @@
|
||||
|
||||
import sys
|
||||
from sys import platform
|
||||
import json
|
||||
from os import mkdir
|
||||
from os.path import expanduser, isdir, join
|
||||
import requests
|
||||
@ -196,6 +197,9 @@ class AppWindow:
|
||||
self.status['text'] = "What are you flying?!" # Shouldn't happen
|
||||
else:
|
||||
# stuff we can do when not docked
|
||||
if __debug__: # Recording
|
||||
with open('%s%s.%s.json' % (data['lastSystem']['name'], data['commander'].get('docked') and '.'+data['lastStarport']['name'] or '', strftime('%Y-%m-%dT%H.%M.%S', localtime())), 'wt') as h:
|
||||
h.write(json.dumps(data, indent=2, sort_keys=True))
|
||||
if config.getint('output') & config.OUT_LOG:
|
||||
flightlog.export(data)
|
||||
if config.getint('output') & config.OUT_SHIP:
|
||||
@ -210,6 +214,9 @@ class AppWindow:
|
||||
elif not data['lastStarport'].get('commodities'):
|
||||
self.status['text'] = "Station doesn't have a market!"
|
||||
else:
|
||||
# Fixup anomalies in the commodity data
|
||||
self.session.fixup(data['lastStarport']['commodities'])
|
||||
|
||||
if config.getint('output') & config.OUT_CSV:
|
||||
bpc.export(data, True)
|
||||
if config.getint('output') & config.OUT_TD:
|
||||
|
15
companion.py
15
companion.py
@ -172,12 +172,7 @@ class Session:
|
||||
self.dump(r)
|
||||
raise ServerError()
|
||||
|
||||
# Recording
|
||||
if __debug__:
|
||||
with open('%s.%s.%s.json' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip(), time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime())), 'wt') as h:
|
||||
h.write(json.dumps(data, indent=2, sort_keys=True))
|
||||
|
||||
return self.fixup(data)
|
||||
return data
|
||||
|
||||
def close(self):
|
||||
self.state = Session.STATE_NONE
|
||||
@ -188,10 +183,8 @@ class Session:
|
||||
pass
|
||||
self.session = None
|
||||
|
||||
|
||||
# Fixup anomalies in the recieved commodity data
|
||||
def fixup(self, data):
|
||||
commodities = data.get('lastStarport') and data['lastStarport'].get('commodities') or []
|
||||
# Fixup in-place anomalies in the recieved commodity data
|
||||
def fixup(self, commodities):
|
||||
i=0
|
||||
while i<len(commodities):
|
||||
commodity = commodities[i]
|
||||
@ -234,7 +227,7 @@ class Session:
|
||||
# Skip the commodity
|
||||
commodities.pop(i)
|
||||
|
||||
return data
|
||||
return commodities
|
||||
|
||||
def dump(self, r):
|
||||
if __debug__:
|
||||
|
Loading…
x
Reference in New Issue
Block a user