1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-18 09:57:40 +03:00

Fix for erroneous "Demand: 1" in EDDN output.

This commit is contained in:
Jonathan Harris 2015-06-05 20:56:00 +01:00
parent bbdacf3a31
commit 750b26ef55
4 changed files with 14 additions and 12 deletions

8
bpc.py
View File

@ -6,7 +6,7 @@ import codecs
import time import time
from config import config from config import config
from companion import commoditymap, bracketmap from companion import categorymap, commoditymap, bracketmap
def export(data, csv=False): def export(data, csv=False):
@ -25,15 +25,15 @@ def export(data, csv=False):
h.write(header) 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 categorymap.get(commodity['categoryname'], True):
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 '',
commodity.get('buyPrice') and int(commodity['buyPrice']) or '', commodity.get('buyPrice') and int(commodity['buyPrice']) or '',
int(commodity['demand']) if commodity.get('demandBracket') else '', int(commodity.get('demand', 0)) if commodity.get('demandBracket') else '',
bracketmap.get(commodity.get('demandBracket'), ''), bracketmap.get(commodity.get('demandBracket'), ''),
int(commodity['stock']) if commodity.get('stockBracket') else '', int(commodity.get('stock', 0)) if commodity.get('stockBracket') else '',
bracketmap.get(commodity.get('stockBracket'), ''), bracketmap.get(commodity.get('stockBracket'), ''),
timestamp)).encode('utf-8')) timestamp)).encode('utf-8'))

View File

@ -22,7 +22,9 @@ holdoff = 120 # be nice
# Map values reported by the Companion interface to names displayed in-game and recognized by trade tools # Map values reported by the Companion interface to names displayed in-game and recognized by trade tools
categorymap = { 'Narcotics': 'Legal Drugs', categorymap = { 'Narcotics': 'Legal Drugs',
'Slaves': 'Slavery', } 'Slaves': 'Slavery',
'NonMarketable': False,
'Salvage': False, }
commoditymap= { 'Agricultural Medicines': 'Agri-Medicines', commoditymap= { 'Agricultural Medicines': 'Agri-Medicines',
'Atmospheric Extractors': 'Atmospheric Processors', 'Atmospheric Extractors': 'Atmospheric Processors',

View File

@ -8,7 +8,7 @@ from sys import platform
import time import time
from config import applongname, appversion, config from config import applongname, appversion, config
from companion import commoditymap, bracketmap from companion import categorymap, commoditymap, bracketmap
upload = 'http://eddn-gateway.elite-markets.net:8080/upload/' upload = 'http://eddn-gateway.elite-markets.net:8080/upload/'
schema = 'http://schemas.elite-markets.net/eddn/commodity/1' schema = 'http://schemas.elite-markets.net/eddn/commodity/1'
@ -35,7 +35,7 @@ def export(data, callback):
for commodity in commodities: for commodity in commodities:
i = i+1 i = i+1
callback('Sending %d/%d' % (i, len(commodities))) callback('Sending %d/%d' % (i, len(commodities)))
if commodity.get('categoryname') and commodity['categoryname'] != 'NonMarketable': if commodity.get('categoryname') and categorymap.get(commodity['categoryname'], True):
msg = { '$schemaRef': schema, msg = { '$schemaRef': schema,
'header': header, 'header': header,
'message': { 'message': {
@ -43,9 +43,9 @@ def export(data, callback):
'stationName': stationName, 'stationName': stationName,
'itemName': commoditymap.get(commodity['name'].strip(), commodity['name'].strip()), 'itemName': commoditymap.get(commodity['name'].strip(), commodity['name'].strip()),
'buyPrice': int(commodity.get('buyPrice', 0)), 'buyPrice': int(commodity.get('buyPrice', 0)),
'stationStock': int(commodity.get('stock', 0)), 'stationStock': commodity.get('stockBracket') and int(commodity.get('stock', 0)),
'sellPrice': int(commodity.get('sellPrice', 0)), 'sellPrice': int(commodity.get('sellPrice', 0)),
'demand': int(commodity.get('demand', 0)), 'demand': commodity.get('demandBracket') and int(commodity.get('demand', 0)),
'timestamp': timestamp, 'timestamp': timestamp,
} }
} }

6
td.py
View File

@ -26,7 +26,7 @@ def export(data):
# sort commodities by category # sort commodities by category
bycategory = defaultdict(list) bycategory = defaultdict(list)
for commodity in data['lastStarport']['commodities']: for commodity in data['lastStarport']['commodities']:
if commodity.get('categoryname') and commodity.get('categoryname') != 'NonMarketable': if commodity.get('categoryname') and categorymap.get(commodity['categoryname'], True):
bycategory[categorymap.get(commodity['categoryname'], commodity['categoryname'])].append(commodity) bycategory[categorymap.get(commodity['categoryname'], commodity['categoryname'])].append(commodity)
for category in sorted(bycategory): for category in sorted(bycategory):
@ -37,9 +37,9 @@ def export(data):
commoditymap.get(commodity['name'].strip(), commodity['name'].strip()), commoditymap.get(commodity['name'].strip(), commodity['name'].strip()),
commodity.get('sellPrice', 0), commodity.get('sellPrice', 0),
commodity.get('buyPrice', 0), commodity.get('buyPrice', 0),
int(commodity.get('demand')) if commodity.get('demandBracket') else '', int(commodity.get('demand', 0)) if commodity.get('demandBracket') else '',
bracketmap.get(commodity.get('demandBracket'), '?')[0], bracketmap.get(commodity.get('demandBracket'), '?')[0],
int(commodity.get('stock')) if commodity.get('stockBracket') else '', int(commodity.get('stock', 0)) if commodity.get('stockBracket') else '',
bracketmap.get(commodity.get('stockBracket'), '-')[0], bracketmap.get(commodity.get('stockBracket'), '-')[0],
timestamp)) timestamp))