mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-13 07:47:14 +03:00
parent
accc361d54
commit
65086be1cd
25
commodity.py
25
commodity.py
@ -14,24 +14,21 @@ bracketmap = {
|
||||
3: 'High',
|
||||
}
|
||||
|
||||
(COMMODITY_DEFAULT, COMMODITY_BPC, COMMODITY_CSV) = range(3)
|
||||
# DEFAULT means semi-colon separation
|
||||
# CSV means comma separation
|
||||
(COMMODITY_DEFAULT, COMMODITY_CSV) = range(2)
|
||||
|
||||
|
||||
def export(data, kind=COMMODITY_DEFAULT, filename=None):
|
||||
querytime = config.getint('querytime') or int(time.time())
|
||||
|
||||
if not filename:
|
||||
kind_str = 'bpc'
|
||||
if kind != COMMODITY_BPC:
|
||||
kind_str = 'csv'
|
||||
|
||||
filename = '{system}.{starport}.{time}.{kind}'.format(
|
||||
system=data['lastSystem']['name'].strip(),
|
||||
starport=data['lastStarport']['name'].strip(),
|
||||
time=time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)),
|
||||
kind=kind_str
|
||||
kind='csv'
|
||||
)
|
||||
|
||||
filename = join(config.get('outdir'), filename)
|
||||
|
||||
if kind == COMMODITY_CSV:
|
||||
@ -39,20 +36,6 @@ def export(data, kind=COMMODITY_DEFAULT, filename=None):
|
||||
header = sep.join(('System', 'Station', 'Commodity', 'Sell', 'Buy', 'Demand', '', 'Supply', '', 'Date', '\n'))
|
||||
rowheader = sep.join((data['lastSystem']['name'], data['lastStarport']['name']))
|
||||
|
||||
elif kind == COMMODITY_BPC:
|
||||
sep = ';'
|
||||
header = sep.join(
|
||||
('userID', 'System', 'Station', 'Commodity', 'Sell', 'Buy', 'Demand', '', 'Supply', '', 'Date\n')
|
||||
)
|
||||
|
||||
cmdr = data['commander']['name'].strip()
|
||||
|
||||
header_cmdr = cmdr
|
||||
if sep in cmdr:
|
||||
header_cmdr = f'"{cmdr}"'
|
||||
|
||||
rowheader = sep.join((header_cmdr, data['lastSystem']['name'], data['lastStarport']['name']))
|
||||
|
||||
else:
|
||||
sep = ','
|
||||
header = sep.join(
|
||||
|
Loading…
x
Reference in New Issue
Block a user