Skip to content

Commit

Permalink
Fix: make linter happy, whitespace, quotes and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gyohng committed Jul 3, 2024
1 parent 7851e6c commit b81f952
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions library.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,21 +384,21 @@ def get_part_details(self, lcsc):

# try retrieving from the cached index first (LCSC Part indexing from FTS5 parts is sloooooow)
try:
rows = cur.execute(f'SELECT lcsc, partsId FROM parts_by_lcsc where lcsc IN ({numbers})').fetchall()
rows = cur.execute(f"SELECT lcsc, partsId FROM parts_by_lcsc where lcsc IN ({numbers})").fetchall()

# orphaned parts found
if len(rows) != len(lcsc):
rowid_by_lcsc = dict(rows)
for lc in lcsc:
if lc not in rowid_by_lcsc:
self.logger.debug(f"LCSC Part `{lc}` not found in the database.")
self.logger.debug("LCSC Part `{}` not found in the database.".format(lc))

numbers = ",".join([f'"{r[0]}"' for r in rows])
return cur.execute(
f'SELECT "LCSC Part", "Stock", "Library Type" FROM parts where rowid IN ({numbers})'
).fetchall()
except Exception as e:
self.logger.debug(f"{e}")
self.logger.debug(repr(e))
pass

# fall back to the direct approach
Expand Down Expand Up @@ -553,24 +553,24 @@ def download(self):
self.logger.debug("Indexing parts table...")
wx.PostEvent(self.parent, UpdateGaugeEvent(value=0))
with contextlib.closing(sqlite3.connect(self.partsdb_file)) as con:
con.execute('DROP TABLE IF EXISTS parts_by_lcsc;')
con.execute('CREATE TABLE IF NOT EXISTS parts_by_lcsc (partsId INTEGER, lcsc TEXT);')
con.execute('DROP INDEX IF EXISTS LCSCpartIdx;')
cur = con.execute('SELECT rowid, `LCSC Part` FROM parts')
con.execute("DROP TABLE IF EXISTS parts_by_lcsc;")
con.execute("CREATE TABLE IF NOT EXISTS parts_by_lcsc (partsId INTEGER, lcsc TEXT);")
con.execute("DROP INDEX IF EXISTS LCSCpartIdx;")
cur = con.execute("SELECT rowid, `LCSC Part` FROM parts")
indexedParts = cur.fetchall()
howMany = len(indexedParts)
progress = 0
for i, r in enumerate(indexedParts):
con.execute('INSERT OR REPLACE INTO parts_by_lcsc (partsId, lcsc) VALUES (?, ?)', (r[0], r[1]))
con.execute("INSERT OR REPLACE INTO parts_by_lcsc (partsId, lcsc) VALUES (?, ?)", (r[0], r[1]))
p = int(i / howMany * 100)
if p > progress:
wx.PostEvent(self.parent, UpdateGaugeEvent(value=p))
progress = p

wx.PostEvent(self.parent, UpdateGaugeEvent(value=100))
self.logger.debug("Finalising database index...")
self.logger.debug("Finalising database index...")
con.commit()
con.execute('CREATE INDEX IF NOT EXISTS LCSCpartIdx ON parts_by_lcsc(lcsc);')
con.execute("CREATE INDEX IF NOT EXISTS LCSCpartIdx ON parts_by_lcsc(lcsc);")
con.commit()
self.logger.debug("Indexing parts table done.")

Expand Down

0 comments on commit b81f952

Please sign in to comment.