ny_forecast 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/find_forecast.rb +21 -10
- data/lib/runner.rb +11 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f19c08c604a704010a530770ac8fd266c16a8206
|
4
|
+
data.tar.gz: 89ee7c424fde365c2b310569e464adc2f0325be8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c28e467140ab181ab8d17a4c9413de6b76476fa28e48e4f0854e81f6c08c7c3e3f6c074ab6f8fc9f53040ab44a999a0d8ca9e45c8f5950f1f782b36c3b2562e
|
7
|
+
data.tar.gz: 2736b315500c83c239078d17353f454cd6a2a265290c24eeb85402644a848bc16ce6ed90a7544606bc4dd5bc8aa14daf0cda1ff42f4252f4b8ae296aae22fe71
|
data/lib/find_forecast.rb
CHANGED
@@ -1,22 +1,24 @@
|
|
1
|
+
require 'pry'
|
1
2
|
require_relative '../config/environment.rb'
|
2
3
|
|
3
4
|
class FindForecast
|
4
|
-
def initialize(
|
5
|
+
def initialize(command)
|
5
6
|
@first_six = Nokogiri::HTML(open("http://www.weather.com/weather/hourbyhour/graph/New+York+NY+USNY0996:1:US"))
|
6
7
|
@next_eighteen = Nokogiri::HTML(open("http://www.weather.com/weather/hourbyhour/graph/New+York+NY+USNY0996:1:US?pagenum=2&nextbeginIndex=6"))
|
7
|
-
|
8
|
-
intro(
|
9
|
-
scrape_forecast(
|
8
|
+
@five_day = Nokogiri::HTML(open("http://www.weather.com/weather/5-day/New+York+NY+USNY0996:1:US"))
|
9
|
+
intro(command)
|
10
|
+
scrape_forecast(command)
|
10
11
|
end
|
11
12
|
|
12
|
-
def intro(
|
13
|
-
introduction = "\nToday's date: #{Date.today}.\nThe weather for the next #{
|
13
|
+
def intro(command)
|
14
|
+
introduction = "\nToday's date: #{Date.today}.\nThe weather for the next #{command} is as follows:\n\n"
|
14
15
|
puts introduction
|
15
16
|
end
|
16
17
|
|
17
|
-
def scrape_forecast(
|
18
|
-
scrape_six
|
19
|
-
|
18
|
+
def scrape_forecast(command)
|
19
|
+
scrape_six if command == "6 hours"
|
20
|
+
scrape_twenty_four if command == "24 hours"
|
21
|
+
scrape_five_days if command == "5 days"
|
20
22
|
end
|
21
23
|
|
22
24
|
def scrape_six
|
@@ -30,7 +32,8 @@ class FindForecast
|
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
def
|
35
|
+
def scrape_twenty_four
|
36
|
+
scrape_six
|
34
37
|
to_delete = @next_eighteen.css("span.wx-date-label").collect {|x| x.text} + @next_eighteen.css("span.wx-day-label").collect {|x| x.text}
|
35
38
|
forecasts = @next_eighteen.css("div.wx-timepart").collect { |section| section.text.gsub(/\n/,'') }
|
36
39
|
forecasts.each_with_index do |forecast, i|
|
@@ -40,4 +43,12 @@ class FindForecast
|
|
40
43
|
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")
|
41
44
|
end
|
42
45
|
end
|
46
|
+
|
47
|
+
def scrape_five_days
|
48
|
+
forecasts = @five_day.css("div.wx-daypart").collect { |section| section.text.gsub(/\n/,'') }
|
49
|
+
forecasts.each_with_index do |forecast, i|
|
50
|
+
puts forecast.gsub("Details","") #.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
|
51
|
+
puts
|
52
|
+
end
|
53
|
+
end
|
43
54
|
end
|
data/lib/runner.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative '../config/environment.rb'
|
2
|
+
VALID = ["6 hours", "24 hours", "5 days"]
|
2
3
|
|
3
4
|
class Runner
|
4
5
|
def interface
|
@@ -6,28 +7,29 @@ class Runner
|
|
6
7
|
puts "======================================="
|
7
8
|
puts "Welcome to NY Forecast"
|
8
9
|
puts
|
9
|
-
puts "You can view the
|
10
|
+
puts "You can view the 6-hour, 24-hour, or 5-day forecast. To view the forecasts,"
|
11
|
+
puts "enter the specific amount of time in the following format: '6 hours', '24"
|
12
|
+
puts "hours', or '5 days'."
|
10
13
|
puts "(Type 'exit' to exit)"
|
11
14
|
|
12
15
|
while on do
|
13
16
|
@user_command = gets.chomp
|
14
17
|
|
15
|
-
if @user_command
|
16
|
-
FindForecast.new(
|
17
|
-
puts "Please enter your next request."
|
18
|
-
|
19
|
-
FindForecast.new(24)
|
20
|
-
puts "Please enter your next request."
|
18
|
+
if VALID.include?(@user_command)
|
19
|
+
FindForecast.new(@user_command)
|
20
|
+
puts "Please enter your next request. Valid requests are '6 hours', '24 hours', "
|
21
|
+
puts "or '5 days'."
|
21
22
|
elsif @user_command == "exit"
|
22
23
|
exit
|
23
24
|
on = false
|
24
25
|
else
|
25
|
-
puts "Invalid request! Please enter '6' or '
|
26
|
+
puts "Invalid request! Please enter '6 hours', '24 hours', or '5 days' to view"
|
27
|
+
puts "the forecasts."
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
32
|
def exit
|
31
|
-
puts "
|
33
|
+
puts "Thank you for using NY Forecast."
|
32
34
|
end
|
33
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ny_forecast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Kohlbrenner
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description: Gathers 6-
|
27
|
+
description: Gathers 6-hour, 24-hour, and 5-day weather forecasts for NYC from weather.com
|
28
28
|
email: chris.kohlbrenner@gmail.com
|
29
29
|
executables:
|
30
30
|
- ny_forecast
|