I suck at python, but hopefully this is something along the right lines...
(bearing in mind, system names are unique and this is easier for me to crib that using the ID, use whatever you want).
Code:
import somestuff
import tradedb
import morestuff
<LOTS OF CODE DOING OTHER STUFF>
# Do systems import
def importSystems(self):
<STUFF BEFORE LOOP>
<BEGIN LOOP>
system = json.loads(line)
sysLookup = tdb.systemByName.get
result = syslookup(system['name'], none)
if not result:
tdb.addLocalSystem(
system['id'], system['name'],
system['x'], system['y'], system['z'],
modified,commit=False,
)
self.modSystems += 1
elif result.posX != system[x] or result.posY != system[y] or result.posZ != system[z]:
tdb.updateLocalSystem(
system['id'], system['name'],
system['x'], system['y'], system['z'],
modified,commit=False,
)
self.modSystems += 1
<GO BACK AROUND LOOP FOR NEXT LINE OF JSON>
if self.modSystems:
tdb.getDB().commit()
<STUFF AFTER LOOP>
#End systems import
<MORE CODE DOING MORE STUFF>
I guess what I'm aiming at here is that KFSOne already wrote the functions to manipulate the database and you should probably be using those, instead of directly accessing the db from the plugin.
Use functions in tradedb.
Only update if the system has moved position in the source data. Otherwise even if modified has changed, it's the same exact system and modified is lying.
Use KFS functionality to hold off on committing to database until we are done (commit=false and tdb.getDB().commit() ) so we only write it out once and otherwise do it in memory.
I guess it doesn't help that the TD api is sparsely documented, but it's there to be used. KFSOne already did the heavy lifting on the database, rather than invent the wheel, we can simply plug into what he's already done.
(Really hoping I make sense and this is useful and not total bum gravy of the worst kind)