From 82d98592fa104795f94b93f14341fd2aae29a887 Mon Sep 17 00:00:00 2001 From: Richard Meadows Date: Thu, 26 Feb 2015 15:29:20 +0000 Subject: [PATCH] Fix for updated farnell pages, added error checking to fail gracefully next time --- farnell.rb | 34 +++++++++++++++++++++------------- parts | 53 ++++++++++++++++++++++++----------------------------- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/farnell.rb b/farnell.rb index a4cac7b..229fba5 100644 --- a/farnell.rb +++ b/farnell.rb @@ -30,30 +30,38 @@ def scrape_farnell (order_code) stock_numbers = @fn_page.css("div #priceWrap ul li strong") stock_locations = @fn_page.css("div #priceWrap ul li") - for i in 0...(stock_numbers.count) + if stock_numbers and stock_locations + for i in 0...(stock_numbers.count) - number = stock_numbers[i].inner_html - location = stock_locations[i].inner_html[/\(.*stock\)/] + number = stock_numbers[i].inner_html + location = stock_locations[i].inner_html[/\(.*stock\)/] - stocks[location] = number + stocks[location] = number + end + item[:stocks] = stocks + else + puts "Stock information not found" end - item[:stocks] = stocks # Pricing prices = Hash.new price_breaks = @fn_page.xpath("//table[@class='pricing ']/tbody/tr/td[@class='qty']") - price_prices = @fn_page.xpath("//table[@class='pricing ']/tbody/tr/td[@class='threeColTd']") + price_prices = @fn_page.xpath("//table[@class='pricing ']/tbody/tr/td[@class='threeColTd pdpPriceRightCol']") - for i in 0...(price_breaks.count) + if price_breaks and price_prices + for i in 0...(price_breaks.count) - min = price_breaks[i].inner_html[/(\d+)(.*-|\+)/, 1].to_i - max = price_breaks[i].inner_html[/-.+?(\d+)/, 1].to_i - max = nil if max == 0 - price = price_prices[i].inner_html[/£\d+\.\d+/] + min = price_breaks[i].inner_html[/(\d+)(.*-|\+)/, 1].to_i + max = price_breaks[i].inner_html[/-.+?(\d+)/, 1].to_i + max = nil if max == 0 + price = price_prices[i].inner_html[/£\d+\.\d+/] - prices[{:min => min, :max => max}] = price + prices[{:min => min, :max => max}] = price + end + item[:prices] = prices + else + puts "Pricing information not found" end - item[:prices] = prices # Order quantities common_info = @fn_page.css("div #priceWrap div #commonInfo p").to_s diff --git a/parts b/parts index f7f6b6c..3e9bca0 100644 --- a/parts +++ b/parts @@ -1,34 +1,29 @@ # Parts List ----- -### Active +--- + +## Actives + +| Part | Description | Farnell # | Quantity Required | Notes +| --- | --- | --- | --- | --- +511-SPV1040T 2 MPPT +511-L6924D013TR 1 Lipo Charge Controller +2400648 2 Buck Converter DRVT = SON-6 TPS62243 +595-TPS3808G25DRVR 1 Vth = 2.33, DRVR = SON-6 +1631683 1 Inverter + +## Passives + +| Part | Description | Farnell # | Quantity Required | Notes +| --- | --- | --- | --- | --- +1463485 0 Lx for MPPT. 0.133Ω esr +2428203 2 Indutcutor for Buck +2309027 4 Solar input cap + +## Items used in breakout verision ONLY | Part | Description | Farnell # | Quantity Required | Notes | --- | --- | --- | --- | --- -2361006 1 All the things! -2414373 0 -2414374 1 -HAB-MAX-M8C 1 -2254940 1 -2367709 1 -2405790 1 -1755607 1 -2118125 1 -2285640 1 -1343091 1 -1865775 1 - 0 -2331442 1 -2331491 1 -1828874 2 -1758945 3 - 0 -1758969 3 -1759380 6 -2362088 1 -1833804 2 -1865279 1 -1515765 2 -1828732 2 -1702644 2 -1494852 0.25 +2293786 10 Test Point +3882615 3 Terminal Block 2 Wire +3882627 0 Terminal Block 3 Wire \ No newline at end of file