Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions examples/two_temperatures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/barr/blocks/bbc_weather.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions lib/barr/controllers/bbc_weather.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion spec/blocks/bbc_weather_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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