diff --git a/examples/two_temperatures.rb b/examples/two_temperatures.rb index 970bf09..b5a81a8 100755 --- a/examples/two_temperatures.rb +++ b/examples/two_temperatures.rb @@ -5,18 +5,21 @@ @man = Barr::Manager.new -nyc = Barr::Blocks::Temperature.new bgcolor: '#42C7AA', - fgcolor: '#FFF', - icon: 'New York: ', - location: '2459115', - interval: 1800 +nyc = Barr::Blocks::BBCWeather.new bgcolor: '#42C7AA', + fgcolor: '#FFF', + icon: 'New York: ', + location: '5128581', + interval: 15 -sanfran = Barr::Blocks::Temperature.new bgcolor: '#92A084', - fgcolor: '#FFF', - icon: 'San Francisco: ', - location: '2487956', - align: :r, - interval: 1800 +sanfran = Barr::Blocks::BBCWeather.new bgcolor: '#92A084', + fgcolor: '#FFF', + icon: 'San Francisco: ', + location: '5391959', + format: '${TEMPERATURE - ${SUMMARY} - ${WINDSPEED} - ${WINDDIRECTION}', + speed_unit: 'kph', + temp_unit: 'f', + align: :r, + interval: 30 @man.add nyc @man.add sanfran diff --git a/lib/barr/blocks/bbc_weather.rb b/lib/barr/blocks/bbc_weather.rb index 21affa8..9581f50 100644 --- a/lib/barr/blocks/bbc_weather.rb +++ b/lib/barr/blocks/bbc_weather.rb @@ -18,7 +18,7 @@ def config def update! op = @controller.output - @output = "%{A:barr_open_url http www.bbc.co.uk\/weather\/#{@location}:}#{format_string_from_hash(op)}%{A}" + @output = "%{A:barr_open_url https www.bbc.co.uk\/weather\/#{@location}:}#{format_string_from_hash(op)}%{A}" end end end diff --git a/lib/barr/controllers/bbc_weather.rb b/lib/barr/controllers/bbc_weather.rb index badf8f9..21cabd2 100644 --- a/lib/barr/controllers/bbc_weather.rb +++ b/lib/barr/controllers/bbc_weather.rb @@ -16,19 +16,21 @@ def run! @thread = Thread.new do loop do begin - url = "http://www.bbc.co.uk/weather/#{@id}" + url = "https://www.bbc.co.uk/weather/0/#{@id}" op = {} noko = Nokogiri::HTML(open(url)) - op[:temperature] = noko.css("div.observationsRecord span.units-value.temperature-value.temperature-value-unit-#{@temp_unit}").text - op[:summary] = noko.css('div.observationsRecord p.weather-type img').attribute('alt').value - op[:windspeed] = noko.css("div.observationsRecord span.speed span.units-values.windspeed-units-values span.windspeed-value-unit-#{@speed_unit}").text - op[:winddirection] = noko.css('div.observationsRecord p.wind-speed span.wind.wind-speed').attribute('data-tooltip-mph').value.split(', ')[1] - op[:humidity] = noko.css('div.observationsRecord p.humidity span.data').text - op[:visibility] = noko.css('div.observationsRecord p.visibility span.data').text - op[:pressure] = noko.css('div.observationsRecord p.pressure span.data').text + op[:temperature] = noko.css("div.wr-value--temperature .wr-value--temperature--#{@temp_unit} .wr-hide-visually").text + op[:summary] = noko.css('.wr-day__weather-type-description-container')[0].text + op[:windspeed] = noko.css("span.wr-wind-speed__icon span[data-unit=#{@speed_unit}]")[0].text + op[:winddirection] = noko.css('span.wind-rose__direction-abbr')[0].text.delete(' ') + + hvp = noko.css('li.wr-c-station-data__observation') + op[:humidity] = hvp[0].text + op[:visibility] = hvp[1].text + op[:pressure] = hvp[2].text File.write(filename, op.to_json) diff --git a/spec/blocks/bbc_weather_spec.rb b/spec/blocks/bbc_weather_spec.rb index 070bad4..55f18df 100644 --- a/spec/blocks/bbc_weather_spec.rb +++ b/spec/blocks/bbc_weather_spec.rb @@ -21,7 +21,7 @@ subject.config subject.controller.update! subject.update! - expect(subject.output).to eq('%{A:barr_open_url http www.bbc.co.uk/weather/123456:}17 C - Nice outside%{A}') + expect(subject.output).to eq('%{A:barr_open_url https www.bbc.co.uk/weather/123456:}17 C - Nice outside%{A}') end end end