From 0a88e3e0ab33aa3dae5c498280bbe3dae74b5161 Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Sun, 19 Jun 2016 15:46:25 +0100 Subject: [PATCH] Support for collating from JSON dump --- EDMC.py | 23 ++++++++++++++++------- collate.py | 4 +++- outfitting.py | 5 +++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/EDMC.py b/EDMC.py index 60a28cb9..3da421ea 100755 --- a/EDMC.py +++ b/EDMC.py @@ -4,6 +4,7 @@ # import argparse +import json import requests import sys from time import time, sleep @@ -12,6 +13,7 @@ from xml.etree import ElementTree import l10n l10n.Translations().install_dummy() +import collate import companion import commodity from commodity import COMMODITY_DEFAULT @@ -46,6 +48,7 @@ try: parser.add_argument('-o', metavar='FILE', help='write station outfitting data to FILE in CSV format') parser.add_argument('-s', metavar='FILE', help='write station shipyard data to FILE in CSV format') parser.add_argument('-t', metavar='FILE', help='write player status to FILE in CSV format') + parser.add_argument('-j', help=argparse.SUPPRESS) # Import JSON dump args = parser.parse_args() if args.version: @@ -65,12 +68,18 @@ try: print '%.2f%s' % (float(''.join(appversion.split('.')[:3])) / 100, latest) # just first three digits sys.exit(EXIT_SUCCESS) - session = companion.Session() - session.login(config.get('username'), config.get('password')) - - querytime = int(time()) - data = session.query() - config.set('querytime', querytime) + if args.j: + # Import and collate from JSON dump + data = json.load(open(args.j)) + collate.addcommodities(data) + collate.addmodules(data) + collate.addships(data) + else: + session = companion.Session() + session.login(config.get('username'), config.get('password')) + querytime = int(time()) + data = session.query() + config.set('querytime', querytime) # Validation if not data.get('commander') or not data['commander'].get('name','').strip(): @@ -124,7 +133,7 @@ try: sys.stderr.write("Station doesn't supply outfitting\n") if args.s: - if has_shipyard and not data['lastStarport'].get('ships'): + if has_shipyard and not data['lastStarport'].get('ships') and not args.j: sleep(SERVER_RETRY) data = session.query() if data['lastStarport'].get('ships'): diff --git a/collate.py b/collate.py index e3df2c1e..78df704b 100755 --- a/collate.py +++ b/collate.py @@ -39,8 +39,10 @@ def addcommodities(data): } old = commodities.get(key) if old: - if new != old: + if new['id'] != old['id'] or new['category'] != old['category']: raise AssertionError('%s: "%s"!="%s"' % (key, new, old)) + elif new['average'] != old['average']: + commodities[key] = new else: commodities[key] = new diff --git a/outfitting.py b/outfitting.py index b605687c..fcd77fc9 100644 --- a/outfitting.py +++ b/outfitting.py @@ -350,9 +350,10 @@ def lookup(module, ship_map, entitled=False): # Extra module data key = (new['name'], 'ship' in new and companion.ship_map.get(name[0]) or None, new['class'], new['rating']) if __debug__: - assert key in moduledata, key m = moduledata.get(key, {}) - if new['name'] == 'Frame Shift Drive': + if not m: + print 'No data for module %s' % str(key) + elif new['name'] == 'Frame Shift Drive': assert 'mass' in m and 'optmass' in m and 'maxfuel' in m and 'fuelmul' in m and 'fuelpower' in m, m else: assert 'mass' in m, m