mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-19 02:17:38 +03:00
Support for collating from JSON dump
This commit is contained in:
parent
4f3f489623
commit
0a88e3e0ab
23
EDMC.py
23
EDMC.py
@ -4,6 +4,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import json
|
||||||
import requests
|
import requests
|
||||||
import sys
|
import sys
|
||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
@ -12,6 +13,7 @@ from xml.etree import ElementTree
|
|||||||
import l10n
|
import l10n
|
||||||
l10n.Translations().install_dummy()
|
l10n.Translations().install_dummy()
|
||||||
|
|
||||||
|
import collate
|
||||||
import companion
|
import companion
|
||||||
import commodity
|
import commodity
|
||||||
from commodity import COMMODITY_DEFAULT
|
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('-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('-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('-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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
@ -65,12 +68,18 @@ try:
|
|||||||
print '%.2f%s' % (float(''.join(appversion.split('.')[:3])) / 100, latest) # just first three digits
|
print '%.2f%s' % (float(''.join(appversion.split('.')[:3])) / 100, latest) # just first three digits
|
||||||
sys.exit(EXIT_SUCCESS)
|
sys.exit(EXIT_SUCCESS)
|
||||||
|
|
||||||
session = companion.Session()
|
if args.j:
|
||||||
session.login(config.get('username'), config.get('password'))
|
# Import and collate from JSON dump
|
||||||
|
data = json.load(open(args.j))
|
||||||
querytime = int(time())
|
collate.addcommodities(data)
|
||||||
data = session.query()
|
collate.addmodules(data)
|
||||||
config.set('querytime', querytime)
|
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
|
# Validation
|
||||||
if not data.get('commander') or not data['commander'].get('name','').strip():
|
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")
|
sys.stderr.write("Station doesn't supply outfitting\n")
|
||||||
|
|
||||||
if args.s:
|
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)
|
sleep(SERVER_RETRY)
|
||||||
data = session.query()
|
data = session.query()
|
||||||
if data['lastStarport'].get('ships'):
|
if data['lastStarport'].get('ships'):
|
||||||
|
@ -39,8 +39,10 @@ def addcommodities(data):
|
|||||||
}
|
}
|
||||||
old = commodities.get(key)
|
old = commodities.get(key)
|
||||||
if old:
|
if old:
|
||||||
if new != old:
|
if new['id'] != old['id'] or new['category'] != old['category']:
|
||||||
raise AssertionError('%s: "%s"!="%s"' % (key, new, old))
|
raise AssertionError('%s: "%s"!="%s"' % (key, new, old))
|
||||||
|
elif new['average'] != old['average']:
|
||||||
|
commodities[key] = new
|
||||||
else:
|
else:
|
||||||
commodities[key] = new
|
commodities[key] = new
|
||||||
|
|
||||||
|
@ -350,9 +350,10 @@ def lookup(module, ship_map, entitled=False):
|
|||||||
# Extra module data
|
# Extra module data
|
||||||
key = (new['name'], 'ship' in new and companion.ship_map.get(name[0]) or None, new['class'], new['rating'])
|
key = (new['name'], 'ship' in new and companion.ship_map.get(name[0]) or None, new['class'], new['rating'])
|
||||||
if __debug__:
|
if __debug__:
|
||||||
assert key in moduledata, key
|
|
||||||
m = moduledata.get(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
|
assert 'mass' in m and 'optmass' in m and 'maxfuel' in m and 'fuelmul' in m and 'fuelpower' in m, m
|
||||||
else:
|
else:
|
||||||
assert 'mass' in m, m
|
assert 'mass' in m, m
|
||||||
|
Loading…
x
Reference in New Issue
Block a user