1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-21 11:27:38 +03:00

Fix BPC output for Cmdr names that use non-ASCII characters.

This commit is contained in:
Jonathan Harris 2015-06-05 02:20:03 +01:00
parent ae4f6904f4
commit cf61ef04cc

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'))
timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(querytime))
if csv:
header = 'System;Station;Commodity;Sell;Buy;Demand;;Supply;;Date;\n'
rowheader = '%s;%s' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip())
else: # bpc
header = 'userID;System;Station;Commodity;Sell;Buy;Demand;;Supply;;Date;\n'
rowheader = '%s;%s;%s' % (data['commander']['name'].replace(';',':').strip(), data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip())
header = 'System;Station;Commodity;Sell;Buy;Demand;;Supply;;Date;\n'
rowheader = '%s;%s' % (data['lastSystem']['name'].strip(), data['lastStarport']['name'].strip())
if not csv: # bpc
header = 'userID;' + header
rowheader = '%s;%s' % (data['commander']['name'].replace(';',':').strip(), rowheader)
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']:
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,
commoditymap.get(commodity['name'].strip(), commodity['name'].strip()),
commodity.get('sellPrice') and int(commodity['sellPrice']) or '',
@ -36,6 +35,6 @@ def export(data, csv=False):
bracketmap.get(commodity.get('demandBracket'), ''),
int(commodity['stock']) if commodity.get('stockBracket') else '',
bracketmap.get(commodity.get('stockBracket'), ''),
timestamp))
timestamp)).encode('utf-8'))
h.close()