22import json
33import os
44
5- import yaegoResistors
5+ import yageoResistors
66import smallPartDb
77
88
@@ -34,10 +34,10 @@ def eng_to_float(x):
3434 # show info
3535 print (partDb )
3636
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 )
37+ myE24Series = yageoResistors . yageoResistors ("K" , "0603" , "F" , "R" , "" , "07" )
38+ ESeries = yageoResistors . E24
39+ E24YaegoNumbers = myE24Series . generateYageoNumbers (ESeries , yageoResistors . MinMaxE24 )
40+ E24Values = myE24Series .generateValues (ESeries , yageoResistors . MinMaxE24 )
4141 categoryName = "Resistors"
4242 kicad_footprint = "Resistor_SMD:R_0603_1608Metric"
4343
@@ -50,7 +50,7 @@ def eng_to_float(x):
5050 if postResp .status_code == 200 :
5151 fpId = json .loads (postResp .text )["id" ]
5252
53- data = { 'comment' : "" , 'name' : "Yaego " }
53+ data = { 'comment' : "" , 'name' : "Yageo " }
5454 postResp = partDb .writeManufacturer (data )
5555 yaegoId = None
5656 if postResp .status_code == 422 :
@@ -74,45 +74,72 @@ def eng_to_float(x):
7474 eda_info ['exclude_from_board' ] = False
7575 eda_info ['exclude_from_sim' ] = False
7676 # Altium
77- # eda_info['kicad_symbol'] = "R_IEEE"
78- # eda_info['kicad_footprint'] = "RESC1608X55N, RESC1608X55L, RESC1608X55M"
77+ eda_info ['kicad_symbol' ] = "R_IEEE"
78+ eda_info ['kicad_footprint' ] = "RESC1608X55N, RESC1608X55L, RESC1608X55M"
7979 # Kicad
80- eda_info ['kicad_symbol' ] = "Device:R"
81- eda_info ['kicad_footprint' ] = kicad_footprint
82-
80+ # eda_info['kicad_symbol'] = "Device:R"
81+ # eda_info['kicad_footprint'] = kicad_footprint
82+
8383 print ("write resistors" )
8484 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" ]
85+ for x , in zip (E24YaegoNumbers ):
86+ postResp = partDb .writePart (name = x , category = categoryName , comment = "generated by script" ) #+ os.path.basename(__file__))
87+ partId [json .loads (postResp .text )["id" ]] = x
88+
89+ #partDb.getParts()
8890
89- partDb .getParts ()
91+ attachmentTypeDatasheet = str (partDb .lookupAttachmentType ("Datasheet" ))
92+ if attachmentTypeDatasheet == None :
93+ print ("Not attachment type Datasheet" )
94+ exit ()
95+ attachmentTypeImage = str (partDb .lookupAttachmentType ("Image" ))
96+ if attachmentTypeImage == None :
97+ print ("Not attachment type Image" )
98+ exit ()
9099
91100 print ("patch resistors" )
92- for v , p in zip (E96Values , partDb .parts ):
93- eda_info ['value' ] = str (eng_to_float (v ))
101+ for v , id in zip (E24Values , partId ):
102+
103+ strValue = str (v )
104+
105+ p = partDb .getPartById (id )[1 ]
106+
107+ eda_info ['value' ] = strValue
94108
95109 part = {}
96110
97111 part ['manufacturer_product_number' ] = p ['name' ]
98112 part ['manufacturer_product_url' ] = manufacturer_product_url
99113 part ['manufacturing_status' ] = manufacturing_status
100- #part['ipn'] = "123"
101- strValue = eng_to_float ( v )
114+ #part['ipn'] = ipn
115+
102116 #strValue = ('%.15f' % strValue).rstrip('0').rstrip('.')
103117 part ['description' ] = "RES " + strValue + " OHM 1% 1/10W 0603"
104118 part ['favorite' ] = False
105119 part ['eda_info' ] = eda_info
106120 part ['footprint' ] = footprint
107121 part ['manufacturer' ] = manufacturer
108122
109- postResp = partDb .patchPart (p [ 'id' ] , data = part )
123+ postResp = partDb .patchPart (id , data = part )
110124
111125 attachments = {}
112126 attachments ['url' ] = "https://www.yageo.com/upload/media/product/productsearch/datasheet/rchip/PYu-RC_51_RoHS_P_5.pdf"
113127 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' ])
128+ attachments ['attachment_type' ] = "/api/attachment_types/" + str (attachmentTypeDatasheet )
129+ attachments ['element' ] = "/api/parts/" + str (id )
130+ postResp = partDb .writeAttachment (name = attachments ['name' ], data = attachments )
131+ attachmentId = json .loads (postResp .text )["id" ]
132+
133+ # download attachment
134+ data = { "upload" : { "downloadUrl" : True }, "url" : attachments ['url' ] }
135+ partDb .patchAttachment (attachmentId , data = data )
136+
137+ attachments = {}
138+ attachments ['becomePreviewIfEmpty' ] = False
139+ attachments ['url' ] = "https://mm.digikey.com/Volume0/opasdata/d220001/medias/images/4848/13_0603-%281608-metric%29.jpg"
140+ attachments ['name' ] = "Yageo0603Resistor.jpg"
141+ attachments ['attachment_type' ] = "/api/attachment_types/" + str (attachmentTypeImage )
142+ attachments ['element' ] = "/api/parts/" + str (id )
116143 postResp = partDb .writeAttachment (name = attachments ['name' ], data = attachments )
117144 attachmentId = json .loads (postResp .text )["id" ]
118145
@@ -175,7 +202,7 @@ def eng_to_float(x):
175202 parameters [13 ]['unit' ] = "%"
176203
177204 for para in parameters :
178- para ['element' ] = "/api/parts/" + str (p [ 'id' ] )
205+ para ['element' ] = "/api/parts/" + str (id )
179206 postResp = partDb .writeParameter (name = para ['name' ], data = para )
180207 # max and min values not written. Perhaps a bug...
181208 # patching is pointless here but stays until sure regarding bug.
@@ -186,6 +213,8 @@ def eng_to_float(x):
186213
187214 del (part )
188215
216+ break
217+
189218
190219 print ("List all parts" )
191220 status = partDb .getParts ()
0 commit comments