Skip to content

Commit

Permalink
Allow unknown star systems if '#allowUnknown' is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Aug 11, 2014
1 parent 61e625e commit 98fc67c
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from tradedb import *
import pprint

allowUnknown = False

tdb = TradeDB(r'.\TradeDangerous.accdb')

categories = dict()
Expand Down Expand Up @@ -37,15 +39,20 @@ def addStar(line):
m = re.match(r'(.+)\s*@\s*(\d+\.\d+)(\s*ly)?', dst)
if m:
dst, dist = m.group(1), m.group(2)
dstID = tdb.getStation(dst).ID
try:
tdb.query("INSERT INTO Links (`from`, `to`, `distLy`) VALUES (%d, %d, %s)" % (srcID, dstID, dist)).commit()
except pypyodbc.IntegrityError:
tdb.query("UPDATE Links SET distLy=%s WHERE from=%d and to=%d" % (dist, srcID, dstID)).commit()
try:
tdb.query("INSERT INTO Links (`from`, `to`) VALUES (%d, %d)" % (dstID, srcID)).commit()
except pypyodbc.IntegrityError:
tdb.query("UPDATE Links SET distLy=%s WHERE from=%d and to=%d" % (dist, dstID, srcID)).commit()
dstID = tdb.getStation(dst).ID
try:
tdb.query("INSERT INTO Links (`from`, `to`, `distLy`) VALUES (%d, %d, %s)" % (srcID, dstID, dist)).commit()
except pypyodbc.IntegrityError:
tdb.query("UPDATE Links SET distLy=%s WHERE from=%d and to=%d" % (dist, srcID, dstID)).commit()
try:
tdb.query("INSERT INTO Links (`from`, `to`, `distLy`) VALUES (%d, %d, %s)" % (dstID, srcID, dist)).commit()
except pypyodbc.IntegrityError:
tdb.query("UPDATE Links SET distLy=%s WHERE from=%d and to=%d" % (dist, dstID, srcID)).commit()
except ValueError as e:
if not allowUnknown:
raise e
print("* Unknown star system: %s" % dst)

def changeStation(name):
global tdb
Expand Down Expand Up @@ -87,6 +94,8 @@ def parseItem(station, cat, line, uiOrder):
if not line:
next
if line[0] == '#':
if line == '#allowUnknown':
allowUnknown = True
next # comment
elif line[0] == '*':
addStar(line[1:])
Expand Down

0 comments on commit 98fc67c

Please sign in to comment.