Merge remote-tracking branch 'hw-template/master'

This commit is contained in:
King Kévin 2014-05-03 13:42:37 +02:00
commit d5b4438399
2 changed files with 11 additions and 6 deletions

View File

@ -151,7 +151,8 @@ def bom2(schematic, attributes)
# generate bom2
list = `gnetlist -g bom2 -Oattribs=#{attributes*','} -q -o - #{schematic}`
list.encode!("UTF-8","ISO-8859-1")
list.gsub!(/(\d[Mkmµ]?)\?/,'\1Ω')
list.gsub!(/(\d[Mkmµ]?)\?/,'\1Ω') # UTF-8 characters like Ω are replaced with ? by gnetlist
list.gsub!(/(https?:\/\/[^:]*):/,'"\1":') # ':' (like in links) are not protected
# parse bom2
csv = CSV.parse(list,{:col_sep => ":"})
csv[1..-1].each do |row|
@ -215,10 +216,11 @@ def octopart(seller,sku)
return to_return
end
DIGIKEY_URL = "http://www.digikey.de/product-detail/en/all/"
def scrape_digikey(sku)
to_return = {stock: nil, currency: "EUR", prices: []}
# get page
url = "http://www.digikey.de/product-detail/en/all/#{sku}/"
url = DIGIKEY_URL+sku
doc = Nokogiri::HTML(open(URI.escape(url)))
# get stock
stock_doc = doc.xpath('//td[@id="quantityavailable"]')[0]
@ -235,10 +237,11 @@ def scrape_digikey(sku)
return to_return
end
FARNELL_URL = "http://de.farnell.com/"
def scrape_farnell(sku)
to_return = {stock: nil, currency: "EUR", prices: []}
# get page
url = "http://de.farnell.com/#{sku}"
url = FARNELL_URL+sku
doc = Nokogiri::HTML(open(URI.escape(url)))
# get stock
stock_doc = doc.xpath('//td[@class="prodDetailAvailability"]')[0]
@ -260,10 +263,11 @@ def scrape_farnell(sku)
return to_return
end
MOUSER_URL = "http://www.mouser.com/Search/ProductDetail.aspx?R=0virtualkey0virtualkey"
def scrape_mouser(sku)
to_return = {stock: nil, currency: "EUR", prices: []}
# get page
url = "http://www.mouser.com/Search/ProductDetail.aspx?R=0virtualkey0virtualkey#{sku}"
url = MOUSER_URL+sku
doc = Nokogiri::HTML(open(URI.escape(url),:allow_redirections => :all))
# get stock
stock_doc = doc.xpath('//table[contains(@id,"availability")]/tr/td')[0]
@ -353,6 +357,7 @@ targets.each do |target|
File.open(t.name,"w") do |notes_file|
notes_data.each do |note|
next unless note['note']
note['note'] = note['note'].gsub('. ',".\n").gsub(/\n+$/,'')
notes_file.puts "#{note['refdes']}:\n#{note['note']}\n\n"
end
end
@ -362,7 +367,7 @@ end
desc "generate BOM file from schematic"
targets.each do |target|
file "#{target[:name]}_bom.csv" => target[:sch] do |t|
attributes = ["category","device","value","description","manufacturer","manufacturer-id","digikey-id","farnell-id","mouser-id"]
attributes = ["category","device","value","description","manufacturer","manufacturer-id","datasheet","digikey-id","farnell-id","mouser-id"]
bom_data = bom2(t.prerequisites[0],attributes)
CSV.open(t.name, "wb") do |csv|
all_attributes = ["refdes","qty"]+attributes

View File

@ -32,7 +32,7 @@ L 340 349 240 349 3 0 0 0 -1 -1
T 0 500 8 10 1 1 0 0 1
refdes=C?
T 0 1100 5 10 0 0 0 0 1
description=electolytic, 470µF, 6.3V, 20%, THT, radial
description=electrolytic, 470µF, 6.3V, 20%, THT, radial
T 500 500 8 10 1 1 0 0 1
value=470µF
T 0 900 8 10 0 0 0 0 1