Skip to content

Commit 1cd941e

Browse files
initial
added files
1 parent 1672d7a commit 1cd941e

File tree

4 files changed

+992
-0
lines changed

4 files changed

+992
-0
lines changed

partDbExample.py

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
import yaml
2+
import json
3+
import os
4+
5+
import yaegoResistors
6+
import smallPartDb
7+
8+
9+
def eng_to_float(x):
10+
if type(x) == float or type(x) == int:
11+
return x
12+
if 'k' in x:
13+
if x.endswith('k'):
14+
return float(x.replace('k', '')) * 1000
15+
if len(x) > 1:
16+
return float(x.replace('k', '.')) * 1000
17+
return 1000.0
18+
if 'M' in x:
19+
if x.endswith('M'):
20+
return float(x.replace('M', '')) * 1000000
21+
if len(x) > 1:
22+
return float(x.replace('M', '.')) * 1000000
23+
return 1000000.0
24+
return float(x)
25+
26+
if __name__ == '__main__':
27+
with open("settings.yaml") as stream:
28+
try:
29+
settings = yaml.safe_load(stream)
30+
except yaml.YAMLError as exc:
31+
raise RuntimeError(exc)
32+
partDb = smallPartDb.smallPartDb(settings['host'], settings['token'])
33+
34+
# show info
35+
print(partDb)
36+
37+
myE96Series = yaegoResistors.yaegoResistors("K", "0603", "F", "R", "", "07")
38+
ESeries = yaegoResistors.E96
39+
E96YaegoNumbers = myE96Series.generateYaegoNumbers(ESeries, yaegoResistors.MinMaxE96)
40+
E96Values = myE96Series.generateValues(ESeries, yaegoResistors.MinMaxE96)
41+
categoryName = "Resistors"
42+
kicad_footprint = "Resistor_SMD:R_0603_1608Metric"
43+
44+
data = { 'name': "0603", 'comment': "", "eda_info": { 'kicad_footprint': kicad_footprint } }
45+
postResp = partDb.writeFootprint(data)
46+
fpId = None
47+
if postResp.status_code == 422:
48+
partDb.getFootprints()
49+
fpId = partDb.lookupFootprint(data['name'])
50+
if postResp.status_code == 200:
51+
fpId = json.loads(postResp.text)["id"]
52+
53+
data = { 'comment': "", 'name': "Yaego" }
54+
postResp = partDb.writeManufacturer(data)
55+
yaegoId = None
56+
if postResp.status_code == 422:
57+
partDb.getManufacturers()
58+
yaegoId = partDb.lookupManufacturer(data['name'])
59+
if postResp.status_code == 200:
60+
yaegoId = json.loads(postResp.text)["id"]
61+
62+
manufacturer = {}
63+
manufacturer['id'] = "/api/manufacturers/" + str(yaegoId)
64+
manufacturing_status = "active"
65+
manufacturer_product_url = "https://www.yageo.com/en/Product/Index/rchip/lead_free"
66+
67+
footprint = {}
68+
footprint['id'] = "/api/footprints/" + str(fpId)
69+
70+
eda_info = {}
71+
eda_info['reference_prefix'] = "R"
72+
eda_info['visibility'] = True
73+
eda_info['exclude_from_bom'] = False
74+
eda_info['exclude_from_board'] = False
75+
eda_info['exclude_from_sim'] = False
76+
# Altium
77+
#eda_info['kicad_symbol'] = "R_IEEE"
78+
#eda_info['kicad_footprint'] = "RESC1608X55N, RESC1608X55L, RESC1608X55M"
79+
# Kicad
80+
eda_info['kicad_symbol'] = "Device:R"
81+
eda_info['kicad_footprint'] = kicad_footprint
82+
83+
print("write resistors")
84+
partId = {}
85+
for x, in zip(E96YaegoNumbers):
86+
postResp = partDb.writePart(name=x, category=categoryName, comment="generated by " + os.path.basename(__file__))
87+
partId[x] = json.loads(postResp.text)["id"]
88+
89+
partDb.getParts()
90+
91+
print("patch resistors")
92+
for v, p in zip(E96Values, partDb.parts):
93+
eda_info['value'] = str(eng_to_float(v))
94+
95+
part = {}
96+
97+
part['manufacturer_product_number'] = p['name']
98+
part['manufacturer_product_url'] = manufacturer_product_url
99+
part['manufacturing_status'] = manufacturing_status
100+
#part['ipn'] = "123"
101+
strValue = eng_to_float(v)
102+
#strValue = ('%.15f' % strValue).rstrip('0').rstrip('.')
103+
part['description'] = "RES " + strValue + " OHM 1% 1/10W 0603"
104+
part['favorite'] = False
105+
part['eda_info'] = eda_info
106+
part['footprint'] = footprint
107+
part['manufacturer'] = manufacturer
108+
109+
postResp = partDb.patchPart(p['id'], data=part)
110+
111+
attachments = {}
112+
attachments['url'] = "https://www.yageo.com/upload/media/product/productsearch/datasheet/rchip/PYu-RC_51_RoHS_P_5.pdf"
113+
attachments['name'] = "PYu-RC_51_RoHS_P_5.pdf"
114+
attachments['attachment_type'] = "/api/attachment_types/1"
115+
attachments['element'] = "/api/parts/" + str(p['id'])
116+
postResp = partDb.writeAttachment(name=attachments['name'], data=attachments)
117+
attachmentId = json.loads(postResp.text)["id"]
118+
119+
# download attachment
120+
data = { "upload": { "downloadUrl": True }, "url": attachments['url'] }
121+
partDb.patchAttachment(attachmentId, data=data)
122+
123+
124+
parameters = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]
125+
parameters[0]['name'] = "Resistance"
126+
parameters[0]['value_typical'] = eng_to_float(v)
127+
parameters[0]['unit'] = "Ohm"
128+
129+
parameters[1]['name'] = "Temperature Coefficient"
130+
parameters[1]['value_min'] = -200
131+
parameters[1]['value_max'] = 200
132+
parameters[1]['unit'] = "ppm/°C"
133+
134+
parameters[2]['name'] = "Operating Temperature"
135+
parameters[2]['value_min'] = -55
136+
parameters[2]['value_max'] = 155
137+
parameters[2]['unit'] = "°C"
138+
139+
parameters[3]['name'] = "Composition"
140+
parameters[3]['value_text'] = "Thick Film"
141+
142+
parameters[4]['name'] = "Height - Seated (Max)"
143+
parameters[4]['value_typical'] = 0.55
144+
parameters[4]['unit'] = "mm"
145+
parameters[4]['value_text'] = "0.022\""
146+
147+
parameters[5]['name'] = "Number of Terminations"
148+
parameters[5]['value_typical'] = 2
149+
150+
parameters[6]['name'] = "Package / Case"
151+
parameters[6]['value_text'] = "0603 (1608 Metric)"
152+
153+
parameters[7]['name'] = "Packaging"
154+
parameters[7]['value_text'] = "Tape & Reel (TR)"
155+
156+
parameters[8]['name'] = "Power"
157+
parameters[8]['value_typical'] = 0.1
158+
parameters[8]['unit'] = "W"
159+
160+
parameters[9]['name'] = "Ratings"
161+
parameters[9]['value_text'] = "7C1 RoHS w/out Exemption (100% Pb-Free)"
162+
163+
parameters[10]['name'] = "Size / Dimension"
164+
parameters[10]['value_text'] = "0.063\" L x 0.031\" W (1.60mm x 0.80mm)"
165+
166+
parameters[11]['name'] = "Base Product Number"
167+
parameters[11]['value_text'] = "RC0603"
168+
169+
parameters[12]['name'] = "Supplier Device Package"
170+
parameters[12]['value_text'] = "0603"
171+
172+
parameters[13]['name'] = "Tolerance"
173+
parameters[13]['value_min'] = -1
174+
parameters[13]['value_max'] = 1
175+
parameters[13]['unit'] = "%"
176+
177+
for para in parameters:
178+
para['element'] = "/api/parts/" + str(p['id'])
179+
postResp = partDb.writeParameter(name=para['name'], data=para)
180+
# max and min values not written. Perhaps a bug...
181+
# patching is pointless here but stays until sure regarding bug.
182+
#print(str(i) + ", p: " + str(p) + ", r: " + str(postResp))
183+
if postResp.status_code == 201 or postResp.status_code == 200:
184+
parameterId = json.loads(postResp.text)["id"]
185+
partDb.patchParameter(parameterId, data=para)
186+
187+
del(part)
188+
189+
190+
print("List all parts")
191+
status = partDb.getParts()
192+
if status.status_code == 200:
193+
for p in partDb.parts:
194+
print(str(p['id']) + ": " + p['name'])
195+
196+
print("get all footprints")
197+
status = partDb.getFootprints()
198+
if status.status_code == 200:
199+
for c in partDb.footprints:
200+
print("id: " + str(c['id']) + ", name: " + c['name'])
201+
202+
print("get all categories")
203+
status = partDb.getCategories()
204+
if status.status_code == 200:
205+
for c in partDb.categories:
206+
print("id: " + str(c['id']) + ", name: " + c['name'] + ", full_path: " + c['full_path'])
207+
208+
print("get all manufacturers")
209+
status = partDb.getManufacturers()
210+
if status.status_code == 200:
211+
for m in partDb.manufacturers:
212+
print("id: " + str(m['id']) + ", name: " + m['name'] )
213+
214+
print("get all attachments")
215+
status = partDb.getAttachments()
216+
if status.status_code == 200:
217+
for m in partDb.attachments:
218+
print("id: " + str(m['id']) + ", name: " + m['name'] )
219+
220+
print("get all footprints")
221+
status = partDb.getFootprints()
222+
if status.status_code == 200:
223+
for f in partDb.footprints:
224+
print("id: " + str(f['id']) + ", name: " + f['name'] )
225+

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
engineering-notation==0.10.0
2+
PyYAML==6.0.1
3+
requests==2.31.0
4+
urllib3==2.2.1

0 commit comments

Comments
 (0)