From cf61ef04cce2b089a60434d77de7ebb99767f573 Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Fri, 5 Jun 2015 02:20:03 +0100 Subject: [PATCH] Fix BPC output for Cmdr names that use non-ASCII characters. --- bpc.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bpc.py b/bpc.py index a7d8850c..60565e35 100644 --- a/bpc.py +++ b/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()