ny_forecast 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ny_forecast.rb +12 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21bd6f5fcf423c740031fd2828cf8606b40e5970
|
4
|
+
data.tar.gz: 1ebc78ca27a0fc8d9512e0b52cc3cde7609b2210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 593b0e421493274c9b496a6dae0b85d933f6a0d97a1c79afc2f1f88efd01a59e81669264ce0251828f5df9478aa8f9c486db9529f992bd967a08b95f98509640
|
7
|
+
data.tar.gz: 2db6f55692992a3ef2efd7bdc2c6e4386a32659237010520b109c274af34aeab358626f171446835db302dd301be4aba12db7b8ce238a960044b9a642a5da32e
|
data/lib/ny_forecast.rb
CHANGED
@@ -4,21 +4,26 @@ require 'open-uri'
|
|
4
4
|
class NYForecast
|
5
5
|
def initialize
|
6
6
|
@doc = Nokogiri::HTML(open("http://www.weather.com/weather/hourbyhour/graph/New+York+NY+USNY0996:1:US"))
|
7
|
+
intro
|
7
8
|
scrape_forecast
|
8
9
|
end
|
9
10
|
|
11
|
+
def intro
|
12
|
+
introduction = "\nToday's date: #{Date.today}.\nThe weather for the next six hours is as follows:\n\n"
|
13
|
+
puts introduction
|
14
|
+
end
|
10
15
|
|
11
16
|
def scrape_forecast
|
12
|
-
|
13
|
-
|
17
|
+
to_delete = @doc.css("span.wx-date-label").collect {|x| x.text} + @doc.css("span.wx-day-label").collect {|x| x.text}
|
18
|
+
|
14
19
|
forecasts = @doc.css("div.wx-timepart").collect { |section| section.text.gsub(/\n/,'') }
|
20
|
+
|
15
21
|
forecasts.each_with_index do |forecast, i|
|
16
|
-
|
17
|
-
|
22
|
+
to_delete.each do |word|
|
23
|
+
forecast.gsub!("#{word}", "")
|
18
24
|
end
|
19
|
-
end
|
20
25
|
|
21
|
-
|
26
|
+
puts forecast.gsub("°F", "°").gsub("AM","AM\n").gsub("PM","PM\n").gsub("FEE", "\nFEE").gsub("°", "°\n").gsub("%", "%\n").gsub("Show 15 Minute Details","").gsub("mph","mph\n\n") if i % 4 == 0
|
27
|
+
end
|
22
28
|
end
|
23
|
-
|
24
29
|
end
|