mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-17 07:41:13 +03:00
Fix BPC output for Cmdr names that use non-ASCII characters.
This commit is contained in:
parent
ae4f6904f4
commit
cf61ef04cc
17
bpc.py
17
bpc.py
@ -15,19 +15,18 @@ def export(data, csv=False):
|
|||||||
filename = join(config.get('outdir'), '%s.%s.%s.%s' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip(), time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)), csv and 'csv' or 'bpc'))
|
filename = join(config.get('outdir'), '%s.%s.%s.%s' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip(), time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)), csv and 'csv' or 'bpc'))
|
||||||
|
|
||||||
timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(querytime))
|
timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(querytime))
|
||||||
if csv:
|
header = 'System;Station;Commodity;Sell;Buy;Demand;;Supply;;Date;\n'
|
||||||
header = 'System;Station;Commodity;Sell;Buy;Demand;;Supply;;Date;\n'
|
rowheader = '%s;%s' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip())
|
||||||
rowheader = '%s;%s' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip())
|
if not csv: # bpc
|
||||||
else: # bpc
|
header = 'userID;' + header
|
||||||
header = 'userID;System;Station;Commodity;Sell;Buy;Demand;;Supply;;Date;\n'
|
rowheader = '%s;%s' % (data['commander']['name'].replace(';',':').strip(), rowheader)
|
||||||
rowheader = '%s;%s;%s' % (data['commander']['name'].replace(';',':').strip(), data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip())
|
|
||||||
|
|
||||||
h = open(filename, 'wt') # codecs can't automatically handle line endings, so encode manually where required
|
h = open(filename, 'wt') # codecs can't automatically handle line endings, so encode manually where required
|
||||||
h.write(header.encode('utf-8'))
|
h.write(header)
|
||||||
|
|
||||||
for commodity in data['lastStarport']['commodities']:
|
for commodity in data['lastStarport']['commodities']:
|
||||||
if commodity.get('categoryname') and commodity['categoryname'] != 'NonMarketable':
|
if commodity.get('categoryname') and commodity['categoryname'] != 'NonMarketable':
|
||||||
h.write('%s;%s;%s;%s;%s;%s;%s;%s;%s;\n' % (
|
h.write(('%s;%s;%s;%s;%s;%s;%s;%s;%s;\n' % (
|
||||||
rowheader,
|
rowheader,
|
||||||
commoditymap.get(commodity['name'].strip(), commodity['name'].strip()),
|
commoditymap.get(commodity['name'].strip(), commodity['name'].strip()),
|
||||||
commodity.get('sellPrice') and int(commodity['sellPrice']) or '',
|
commodity.get('sellPrice') and int(commodity['sellPrice']) or '',
|
||||||
@ -36,6 +35,6 @@ def export(data, csv=False):
|
|||||||
bracketmap.get(commodity.get('demandBracket'), ''),
|
bracketmap.get(commodity.get('demandBracket'), ''),
|
||||||
int(commodity['stock']) if commodity.get('stockBracket') else '',
|
int(commodity['stock']) if commodity.get('stockBracket') else '',
|
||||||
bracketmap.get(commodity.get('stockBracket'), ''),
|
bracketmap.get(commodity.get('stockBracket'), ''),
|
||||||
timestamp))
|
timestamp)).encode('utf-8'))
|
||||||
|
|
||||||
h.close()
|
h.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user