mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2026-11-04 01:42:26 +03:00
Move recording and fixup of commodity data to top-level.
This commit is contained in:
1 parent
437997e963
commit
5ca37ed3bd
2 files changed
+11
-11
No files matched your search
@@ -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:
|
||||
|
||||
+4
-11
@@ -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__:
|
||||
|
||||
Reference in new issue
Block a user