ny_forecast 0.0.3 → 0.0.4

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/find_forecast.rb +21 -10
  3. data/lib/runner.rb +11 -9
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 265c834c132adf9a24dbd6b2af51b5aabb94c57d
4
- data.tar.gz: cfcb8dc03ce765a84893561e2574b78e4aa2e126
3
+ metadata.gz: f19c08c604a704010a530770ac8fd266c16a8206
4
+ data.tar.gz: 89ee7c424fde365c2b310569e464adc2f0325be8
5
5
  SHA512:
6
- metadata.gz: fe6dea451461aa3a03f5f7a9de13d4f78b5c22e8f0d7537fdcac724cbae360019e83b3e1f730c25219c847fc1930b6097c3a45d021ee85a8e27f274b9d6d5e43
7
- data.tar.gz: 77bf24921ef2668ddcd23c3272ccdd1c969538e6b98170a8e0e445087526b87805d436621d936be9a7d7de87d34f4eae65ffbb3e91bea63fc7549bcbbd25c554
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(hour)
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(hour)
9
- scrape_forecast(hour)
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(hour)
13
- introduction = "\nToday's date: #{Date.today}.\nThe weather for the next #{hour} hours is as follows:\n\n"
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(hour)
18
- scrape_six
19
- scrape_eighteen if hour == 24
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 scrape_eighteen
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 hourly forecasts by entering '6' or '24' for 6-hour or 24-hour forecasts."
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 == '6'
16
- FindForecast.new(6)
17
- puts "Please enter your next request."
18
- elsif @user_command == '24'
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 '24' to view the 6-hour or 24-hour forecasts."
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 "Thanks for using NY Forecast"
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.3
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- and 24-hour weather forecasts for NYC from weather.com
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