Skip to content

Instantly share code, notes, and snippets.

@lynaghk
Created February 6, 2021 07:37
Show Gist options
  • Save lynaghk/ef2a4aa1776a20e9837d1e282fb09040 to your computer and use it in GitHub Desktop.
Save lynaghk/ef2a4aa1776a20e9837d1e282fb09040 to your computer and use it in GitHub Desktop.
Download JLCPCB part library as a spreadsheet (https://jlcpcb.com/parts) then turn it into a sqlite database so you can search/view/sort parts using https://sqlitebrowser.org/
#!/usr/bin/env python
import xlrd
import os
import sys
import csv
import re
re_px = re.compile(":([0-9.]+)")
with xlrd.open_workbook(sys.argv[1]) as wb:
sh = wb.sheet_by_index(0)
px_idx = sh.row_values(0).index("Price")
with open("jlcpcb.csv", 'w', newline="") as f:
col = csv.writer(f)
# write header
labels = sh.row_values(0)
labels.insert(px_idx, "Px")
col.writerow(labels)
for row in range(1, sh.nrows):
vals = sh.row_values(row)
m = re_px.search(vals[px_idx])
px = m.group(1) if m else vals[px_idx]
vals.insert(px_idx, px)
col.writerow(vals)
# TODO, have python run this
print(
"""
sqlite3 jlcpcb.db << EOF
.separator ","
.import jlcpcb.csv parts
EOF
""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment