Skip to content

Commit

Permalink
Merged kfsone/tradedangerous into master
Browse files Browse the repository at this point in the history
  • Loading branch information
anothermindbomb committed Aug 16, 2014
2 parents 293407a + 11c3736 commit bc5e114
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Binary file modified TradeDangerous.accdb
Binary file not shown.
3 changes: 2 additions & 1 deletion import.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
rejectUnknown = False

tdb = TradeDB(r'.\TradeDangerous.accdb')
sqlEscapeRe = re.compile(r'([\\\'\"%;])')

categories = dict()
for row in tdb.fetch_all("""
Expand Down Expand Up @@ -84,7 +85,7 @@ def changeStation(line):
try:
station = tdb.getStation(stnName)
except LookupError:
tdb.query("INSERT INTO Stations (system, station) VALUES ('%s', '%s')" % (sysName, stnName)).commit()
tdb.query("INSERT INTO Stations (system, station) VALUES (?, ?)", [sysName, stnName]).commit()
print("Added %s/%s" % (sysName, stnName))
tdb.load()
station = tdb.getStation(stnName)
Expand Down
18 changes: 11 additions & 7 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Station(object):
""" Describes a station within a given system along with what trade
opportunities it presents. """
def __init__(self, ID, system, station):
self.ID, self.system, self.station = ID, system, station.replace(' ', '')
self.ID, self.system, self.station = ID, system, station
self.trades = {}
self.stations = []
system.addStation(self)
Expand Down Expand Up @@ -96,15 +96,15 @@ def getDestinations(self, maxJumps=None, maxLy=None, maxLyPer=None):
maxJumpDist = float(maxLyPer or sys.maxint)
while not openList.empty():
(sys, jumps, dist) = openList.get()
if maxJumps and len(jumps) - 1 > maxJumps:
if maxJumps and len(jumps) > maxJumps:
continue
if maxLy and dist > maxLy:
continue
jumps = list(jumps + [sys])
for stn in sys.stations:
if stn != self:
destStations.append([sys, stn, jumps, dist])
if (maxJumps and len(jumps) >= maxJumps):
if (maxJumps and len(jumps) > maxJumps):
continue
for (destSys, destDist) in sys.links.items():
if destDist > maxJumpDist:
Expand Down Expand Up @@ -145,7 +145,7 @@ def load(self, avoidItems=[], avoidSystems=[], avoidStations=[], ignoreLinks=Fal
FROM Stations AS frmSys, Links, Stations as toSys
WHERE frmSys.ID = Links.from AND toSys.ID = Links.to""")
for row in cur:
if row[0] in self.systems:
if row[0] in self.systems and row[1] in self.systems:
self.systems[row[0]].addLink(self.systems[row[1]], float(row[2] or 5))

cur.execute('SELECT id, system, station FROM Stations')
Expand Down Expand Up @@ -255,10 +255,10 @@ def getStation(self, name):
return system.stations[0]


def query(self, sql):
def query(self, *args):
conn = pypyodbc.connect(self.path)
cur = conn.cursor()
cur.execute(sql)
cur.execute(*args)
return cur


Expand All @@ -271,7 +271,11 @@ def list_search(self, listType, lookup, values):
match = None
needle = self.normalized_str(lookup)
for val in values:
if self.normalized_str(val).find(needle) > -1:
normVal = self.normalized_str(val)
if normVal.find(needle) > -1:
# If this is an exact match, ignore ambiguities.
if normVal == needle:
return val
if match:
raise ValueError("Ambiguity: %s '%s' could match %s or %s" % (
listType, lookup, match, val))
Expand Down

0 comments on commit bc5e114

Please sign in to comment.