Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeonus committed Oct 28, 2018
2 parents 2c897f8 + 2b617e8 commit 8a43404
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions plugins/eddblink_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,19 +630,28 @@ def importListings(self, listings_file):

progress = 0
total = 1
if listings_file == LISTINGS:
from_live = 0
else:
from_live = 1

def blocks(f, size = 65536):
while True:
b = f.read(size)
if not b: break
yield b

with open(str(self.dataPath / listings_file), "r",encoding = "utf-8",errors = 'ignore') as f:
total += (sum(bl.count("\n") for bl in blocks(f)))

with open(str(self.dataPath / listings_file), "rU") as fh:
if self.getOption("progbar"):
prog = pbar.Progress(total, 50)
listings = csv.DictReader(fh)

cur_station = -1
station_items = dict()

for listing in listings:
if self.getOption("progbar"):
prog.increment(1, postfix=lambda value, goal: " " + str(round(value / total * 100)) + "%")
Expand All @@ -658,8 +667,20 @@ def blocks(f, size = 65536):
supply_price = int(listing['buy_price'])
supply_units = int(listing['supply'])
supply_level = int(listing['supply_bracket']) if listing['supply_bracket'] != '' else -1
#from_live = 0 if listings_file == LISTINGS else 1
from_live = 0

if station_id != cur_station:
for item in station_items:
if not item:
self.execute("DELETE from StationItem WHERE station_id = ? and item_id = ?", (station_id, item))
del station_items, cur_station
cur_station = station_id
station_items = dict()
cursor = self.execute("SELECT item_id from StationItem WHERE station_id = ?", (station_id,))
for item in cursor:
station_items[item] = False
del cursor

station_items[item_id] = True

result = self.execute("SELECT modified FROM StationItem WHERE station_id = ? AND item_id = ?", (station_id, item_id)).fetchone()
if result:
Expand Down Expand Up @@ -707,6 +728,7 @@ def blocks(f, size = 65536):
prog.increment(1, postfix=lambda value, goal: " " + str(round(value / total * 100)) + "%")
prog.clear()

del from_live
self.updated['Listings'] = True
tdenv.NOTE("Finished processing market data. End time = {}", datetime.datetime.now())

Expand Down Expand Up @@ -740,6 +762,9 @@ def run(self):
self.execute("ALTER TABLE Station ADD type_id INTEGER DEFAULT 0 NOT NULL")
except sqlite3.OperationalError:
pass
except sqlite3.DatabaseError as e:
self.options['clean'] = True
tdenv.NOTE("Cleaning database: ",str(e))

if self.getOption("clean"):
# Rebuild the tables from scratch. Must be done on first run of plugin.
Expand Down

0 comments on commit 8a43404

Please sign in to comment.