downloader for molex connectors

This commit is contained in:
Brendan Haines 2022-09-22 20:05:31 -06:00
parent 5fb3448f9e
commit f8fe77771f

View File

@ -1,12 +1,13 @@
import time
import zipfile
from datetime import datetime
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Optional, Union
from zipfile import ZipFile
import numpy as np
import regex as re
import requests
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import By
@ -15,20 +16,47 @@ from selenium.webdriver.support.wait import WebDriverWait
dir_ = Path(__file__).parent
rng = np.random.default_rng()
PARTS = [
*[f"TSW-1{i:02d}-07-L-S" for i in range(1, 50)],
*[f"TSW-1{i:02d}-07-L-D" for i in range(1, 50)],
*[f"TSW-1{i:02d}-07-L-T" for i in range(1, 50)],
*[f"TSW-1{i:02d}-07-L-Q" for i in range(1, 50)],
*[f"TSW-2{i:02d}-07-L-S" for i in range(2, 25)],
*[f"TSW-2{i:02d}-07-L-D" for i in range(2, 25)],
*[f"TSW-2{i:02d}-07-L-T" for i in range(2, 25)],
*[f"TSW-2{i:02d}-07-L-Q" for i in range(2, 25)],
PARTS_SAMTEC = [
# Pin Headers
*[f"TSW-1{i:02d}-07-L-S" for i in range(1, 51)],
*[f"TSW-1{i:02d}-07-L-D" for i in range(1, 51)],
# *[f"TSW-1{i:02d}-07-L-T" for i in range(1, 51)],
# *[f"TSW-1{i:02d}-07-L-Q" for i in range(1, 51)],
*[f"TSW-2{i:02d}-07-L-S" for i in range(2, 26)],
*[f"TSW-2{i:02d}-07-L-D" for i in range(2, 26)],
# *[f"TSW-2{i:02d}-07-L-T" for i in range(2, 26)],
# *[f"TSW-2{i:02d}-07-L-Q" for i in range(2, 26)],
# Sockets
# SSW
# SMH
# Discrete Wire
# TFM
# SFM
# High Speed Board to Board
# *np.flatten(
# [[f"LSHM-1{i:02d}-{h:02.1f}-L-DV-A-S-TR" for i in [5, 10, 20, 30, 40, 50]] for h in [2.5, 3.0, 4.0, 6.0]]
# ),
]
PARTS_MOLEX = [
# Micro-Fit 3.0 Single Row Headers
*[f"43650-{i:02d}10" for i in range(2, 13)], # 1 row, RA, press-fit retention clip
*[f"43650-{i:02d}13" for i in range(2, 13)], # 1 row, RA, solder tab
*[f"43650-{i:02d}22" for i in range(2, 13)], # 1 row, Vertical, press-fit retention clip
*[f"43650-{i:02d}25" for i in range(2, 13)], # 1 row, RA, solder tab
# Micro-Fit 3.0 Dual Row Headers
*[f"43045-{i:02d}07" for i in range(2, 25, 2)], # 2 row, RA, press-fit retention clip
*[f"43045-{i:02d}10" for i in range(2, 25, 2)], # 2 row, RA, solder tab
*[f"43045-{i:02d}16" for i in range(2, 25, 2)], # 2 row, Vertical, press-fit retention clip
*[f"43045-{i:02d}19" for i in range(2, 25, 2)], # 2 row, RA, solder tab
# Eurostyle 5.08mm Headers
# "39531-0002",
# Eurostyle 5.08mm Plugs
# "39530-0002",
]
URL_STEP = "https://www.snapeda.com/parts/{0}/Samtec/embed/?ref=samtec"
def download_step_samtec(part: str):
def download_step_samtec(part: str) -> None:
print(part)
with TemporaryDirectory(prefix=str(dir_ / "tmp") + "/") as tmp:
tmp = Path(tmp)
@ -43,7 +71,7 @@ def download_step_samtec(part: str):
with webdriver.Chrome(
options=chrome_options,
) as browser:
browser.get(URL_STEP.format(part.upper()))
browser.get(f"https://www.snapeda.com/parts/{part.upper()}/Samtec/embed/?ref=samtec")
wait = WebDriverWait(browser, 30)
wait.until(
EC.element_to_be_clickable(browser.find_element(by=By.ID, value="download_traceparts_3d_model"))
@ -63,7 +91,7 @@ def download_step_samtec(part: str):
# print(list((Path(tmp).glob("*.zip"))))
# unzip
with ZipFile(list((Path(tmp).glob("*.zip")))[0]) as zip:
with zipfile.ZipFile(list((Path(tmp).glob("*.zip")))[0]) as zip:
zip.extractall(path=str(tmp))
# move
@ -75,16 +103,48 @@ def download_step_samtec(part: str):
(Path(tmp) / filename).rename(dir_ / "samtec.pretty" / "3dshapes" / filename)
def download_step_molex(part: Union[str, int]) -> None:
# remove dash
part = f'{int(str(part).replace("-", "")):09d}'
print(part)
with TemporaryDirectory(prefix=str(dir_ / "tmp") + "/") as tmp:
tmp = Path(tmp)
for p in [part, part[:5] + "-" + part[5:]]:
try:
zipname = f"{part}_stp.zip"
# download
with open(tmp / zipname, "wb") as f:
f.write(requests.get(f"https://www.molex.com/pdm_docs/stp/{p}_stp.zip").content)
# unzip
with zipfile.ZipFile(tmp / zipname) as zip:
zip.extractall(path=str(tmp))
# move
filename = f"{part}.stp"
(Path(tmp) / filename).rename(dir_ / "molex.pretty" / "3dshapes" / filename)
return
except zipfile.BadZipFile:
print(f"zip does not exist for part {p}")
raise ValueError(f"Could not download .stp for part {part}")
now = datetime.now()
INCH = 25.4
SILK_WIDTH = 0.007 * INCH
def footprint_samtec(part: str, lib: Optional[Union[Path, str]] = None) -> str:
if part[:4].upper() == "TSW-":
if any([part.startswith(s) for s in ["TSW-", "HTSW-"]]):
# pinheader
match = re.match(
r"(H?)TSW-([12])(\d\d)-(\d\d)-([FLGT])-([SDTQ])(-RA)?(-RE)?(-NA)?(-LL)?(-LC)?(-LA)?(-(\d\d\d))?",
r"(H?)TSW-([12])(\d\d)-(\d\d)-([FLGT])-([SDTQ])(-R[AE])?(-NA)?(-LL)?(-LC)?(-LA)?(-(\d\d\d))?",
part.upper(),
)
high_temp = match[1] != ""
@ -159,18 +219,27 @@ def footprint_samtec(part: str, lib: Optional[Union[Path, str]] = None) -> str:
)
+ "\n"
)
elif any([part.startswith(s) for s in ["SSW-"]]):
# socket
raise NotImplementedError()
else:
raise ValueError(f"Unknown part family for {part}")
if __name__ == "__main__":
for part in PARTS:
time.sleep(rng.random() * 3)
download_step_samtec(part)
footprint_samtec(part)
from multiprocessing import Pool
# from multiprocessing import Pool
# pool = Pool(10)
# pool.map(download_step_samtec, PARTS)
# pool.map(footprint_samtec, PARTS)
# pool.close()
pool = Pool(10)
# for part in PARTS_SAMTEC:
# time.sleep(rng.random() * 3)
# download_step_samtec(part)
# footprint_samtec(part)
# pool.map(download_step_samtec, PARTS_SAMTEC)
# pool.map(footprint_samtec, PARTS_SAMTEC)
# for part in PARTS_MOLEX:
# download_step_molex(part)
pool.map(download_step_molex, PARTS_MOLEX)
pool.close()