Skip to content

Commit

Permalink
Fix for updated farnell pages, added error checking to fail gracefull…
Browse files Browse the repository at this point in the history
…y next time
  • Loading branch information
richardeoin committed Feb 26, 2015
1 parent c0ba65f commit 82d9859
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 42 deletions.
34 changes: 21 additions & 13 deletions farnell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 24 additions & 29 deletions parts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 82d9859

Please sign in to comment.