-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpartDbExample.py
More file actions
265 lines (210 loc) · 9.96 KB
/
partDbExample.py
File metadata and controls
265 lines (210 loc) · 9.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import yaml
import json
import os
import yageoResistors
import smallPartDb
doResistors = False
def eng_to_float(x):
if type(x) == float or type(x) == int:
return x
if 'k' in x:
if x.endswith('k'):
return float(x.replace('k', '')) * 1000
if len(x) > 1:
return float(x.replace('k', '.')) * 1000
return 1000.0
if 'M' in x:
if x.endswith('M'):
return float(x.replace('M', '')) * 1000000
if len(x) > 1:
return float(x.replace('M', '.')) * 1000000
return 1000000.0
return float(x)
if __name__ == '__main__':
with open("settings.yaml") as stream:
try:
settings = yaml.safe_load(stream)
except yaml.YAMLError as exc:
raise RuntimeError(exc)
partDb = smallPartDb.smallPartDb(settings['host'], settings['token'])
# show info
print(partDb)
if(doResistors):
myE24Series = yageoResistors.yageoResistors("K", "0603", "F", "R", "", "07")
ESeries = yageoResistors.E24
E24YaegoNumbers = myE24Series.generateYageoNumbers(ESeries, yageoResistors.MinMaxE24)
E24Values = myE24Series.generateValues(ESeries, yageoResistors.MinMaxE24)
categoryName = "Resistors"
kicad_footprint = "Resistor_SMD:R_0603_1608Metric"
data = { 'name': "0603", 'comment': "", "eda_info": { 'kicad_footprint': kicad_footprint } }
postResp = partDb.writeFootprint(data)
fpId = None
if postResp.status_code == 422:
partDb.getFootprints()
fpId = partDb.lookupFootprint(data['name'])
if postResp.status_code == 200:
fpId = json.loads(postResp.text)["id"]
data = { 'comment': "", 'name': "Yageo" }
postResp = partDb.writeManufacturer(data)
yaegoId = None
if postResp.status_code == 422:
partDb.getManufacturers()
yaegoId = partDb.lookupManufacturer(data['name'])
if postResp.status_code == 200:
yaegoId = json.loads(postResp.text)["id"]
manufacturer = {}
manufacturer['id'] = "/api/manufacturers/" + str(yaegoId)
manufacturing_status = "active"
manufacturer_product_url = "https://www.yageo.com/en/Product/Index/rchip/lead_free"
footprint = {}
footprint['id'] = "/api/footprints/" + str(fpId)
eda_info = {}
eda_info['reference_prefix'] = "R"
eda_info['visibility'] = True
eda_info['exclude_from_bom'] = False
eda_info['exclude_from_board'] = False
eda_info['exclude_from_sim'] = False
# Altium
eda_info['kicad_symbol'] = "R_IEEE"
eda_info['kicad_footprint'] = "RESC1608X55N, RESC1608X55L, RESC1608X55M"
# Kicad
#eda_info['kicad_symbol'] = "Device:R"
#eda_info['kicad_footprint'] = kicad_footprint
print("write resistors")
partId = {}
for x, in zip(E24YaegoNumbers):
postResp = partDb.writePart(name=x, category=categoryName, comment="generated by script") #+ os.path.basename(__file__))
partId[json.loads(postResp.text)["id"]] = x
#partDb.getParts()
attachmentTypeDatasheet = str(partDb.lookupAttachmentType("Datasheet"))
if attachmentTypeDatasheet == None:
print("Not attachment type Datasheet")
exit()
attachmentTypeImage = str(partDb.lookupAttachmentType("Image"))
if attachmentTypeImage == None:
print("Not attachment type Image")
exit()
print("patch resistors")
for v, id in zip(E24Values, partId):
strValue = str(v)
p = partDb.getPartById(id)[1]
eda_info['value'] = strValue
part = {}
part['manufacturer_product_number'] = p['name']
part['manufacturer_product_url'] = manufacturer_product_url
part['manufacturing_status'] = manufacturing_status
#part['ipn'] = ipn
#strValue = ('%.15f' % strValue).rstrip('0').rstrip('.')
part['description'] = "RES " + strValue + " OHM 1% 1/10W 0603"
part['favorite'] = False
part['eda_info'] = eda_info
part['footprint'] = footprint
part['manufacturer'] = manufacturer
postResp = partDb.patchPart(id, data=part)
attachments = {}
attachments['url'] = "https://www.yageo.com/upload/media/product/productsearch/datasheet/rchip/PYu-RC_51_RoHS_P_5.pdf"
attachments['name'] = "PYu-RC_51_RoHS_P_5.pdf"
attachments['attachment_type'] = "/api/attachment_types/" + str(attachmentTypeDatasheet)
attachments['element'] = "/api/parts/" + str(id)
postResp = partDb.writeAttachment(name=attachments['name'], data=attachments)
attachmentId = json.loads(postResp.text)["id"]
# download attachment
data = { "upload": { "downloadUrl": True }, "url": attachments['url'] }
partDb.patchAttachment(attachmentId, data=data)
attachments = {}
attachments['becomePreviewIfEmpty'] = False
attachments['url'] = "https://mm.digikey.com/Volume0/opasdata/d220001/medias/images/4848/13_0603-%281608-metric%29.jpg"
attachments['name'] = "Yageo0603Resistor.jpg"
attachments['attachment_type'] = "/api/attachment_types/" + str(attachmentTypeImage)
attachments['element'] = "/api/parts/" + str(id)
postResp = partDb.writeAttachment(name=attachments['name'], data=attachments)
attachmentId = json.loads(postResp.text)["id"]
# download attachment
data = { "upload": { "downloadUrl": True }, "url": attachments['url'] }
partDb.patchAttachment(attachmentId, data=data)
parameters = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]
parameters[0]['name'] = "Resistance"
parameters[0]['value_typical'] = eng_to_float(v)
parameters[0]['unit'] = "Ohm"
parameters[1]['name'] = "Temperature Coefficient"
parameters[1]['value_min'] = -200
parameters[1]['value_max'] = 200
parameters[1]['unit'] = "ppm/°C"
parameters[2]['name'] = "Operating Temperature"
parameters[2]['value_min'] = -55
parameters[2]['value_max'] = 155
parameters[2]['unit'] = "°C"
parameters[3]['name'] = "Composition"
parameters[3]['value_text'] = "Thick Film"
parameters[4]['name'] = "Height - Seated (Max)"
parameters[4]['value_typical'] = 0.55
parameters[4]['unit'] = "mm"
parameters[4]['value_text'] = "0.022\""
parameters[5]['name'] = "Number of Terminations"
parameters[5]['value_typical'] = 2
parameters[6]['name'] = "Package / Case"
parameters[6]['value_text'] = "0603 (1608 Metric)"
parameters[7]['name'] = "Packaging"
parameters[7]['value_text'] = "Tape & Reel (TR)"
parameters[8]['name'] = "Power"
parameters[8]['value_typical'] = 0.1
parameters[8]['unit'] = "W"
parameters[9]['name'] = "Ratings"
parameters[9]['value_text'] = "7C1 RoHS w/out Exemption (100% Pb-Free)"
parameters[10]['name'] = "Size / Dimension"
parameters[10]['value_text'] = "0.063\" L x 0.031\" W (1.60mm x 0.80mm)"
parameters[11]['name'] = "Base Product Number"
parameters[11]['value_text'] = "RC0603"
parameters[12]['name'] = "Supplier Device Package"
parameters[12]['value_text'] = "0603"
parameters[13]['name'] = "Tolerance"
parameters[13]['value_min'] = -1
parameters[13]['value_max'] = 1
parameters[13]['unit'] = "%"
for para in parameters:
para['element'] = "/api/parts/" + str(id)
postResp = partDb.writeParameter(name=para['name'], data=para)
# max and min values not written. Perhaps a bug...
# patching is pointless here but stays until sure regarding bug.
#print(str(i) + ", p: " + str(p) + ", r: " + str(postResp))
if postResp.status_code == 201 or postResp.status_code == 200:
parameterId = json.loads(postResp.text)["id"]
partDb.patchParameter(parameterId, data=para)
del(part)
break
print("List all parts")
status = partDb.getParts()
if status.status_code == 200:
for p in partDb.parts:
print(str(p['id']) + ": " + p['name'])
print("get all categories")
status = partDb.getCategories()
if status.status_code == 200:
for c in partDb.categories:
print("id: " + str(c['id']) + ", name: " + c['name'] + ", full_path: " + c['full_path'])
print("get all manufacturers")
status = partDb.getManufacturers()
if status.status_code == 200:
for m in partDb.manufacturers:
print("id: " + str(m['id']) + ", name: " + m['name'] )
print("get all attachments")
status = partDb.getAttachments()
if status.status_code == 200:
for m in partDb.attachments:
print("id: " + str(m['id']) + ", name: " + m['name'] )
print("get all footprints")
status = partDb.getFootprints()
if status.status_code == 200:
for f in partDb.footprints:
print("id: " + str(f['id']) + ", name: " + f['name'] )
print("get all storageLocations")
status = partDb.getStore_Location()
if status.status_code == 200:
for f in partDb.storageLocation:
print("id: " + str(f['id']) + ", name: " + f['name'])
storageLoaction = "LDOs" # Put here the name of your storage location
print("get all parts on x storageLocation")
status = partDb.getPartsByStorage(storageLoaction)
if status.status_code == 200:
for c in partDb.partsbyStorage:
print("id: " + str(c['id']) + ", name: " + c['name'])