ny_forecast 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21bd6f5fcf423c740031fd2828cf8606b40e5970
4
- data.tar.gz: 1ebc78ca27a0fc8d9512e0b52cc3cde7609b2210
3
+ metadata.gz: 265c834c132adf9a24dbd6b2af51b5aabb94c57d
4
+ data.tar.gz: cfcb8dc03ce765a84893561e2574b78e4aa2e126
5
5
  SHA512:
6
- metadata.gz: 593b0e421493274c9b496a6dae0b85d933f6a0d97a1c79afc2f1f88efd01a59e81669264ce0251828f5df9478aa8f9c486db9529f992bd967a08b95f98509640
7
- data.tar.gz: 2db6f55692992a3ef2efd7bdc2c6e4386a32659237010520b109c274af34aeab358626f171446835db302dd301be4aba12db7b8ce238a960044b9a642a5da32e
6
+ metadata.gz: fe6dea451461aa3a03f5f7a9de13d4f78b5c22e8f0d7537fdcac724cbae360019e83b3e1f730c25219c847fc1930b6097c3a45d021ee85a8e27f274b9d6d5e43
7
+ data.tar.gz: 77bf24921ef2668ddcd23c3272ccdd1c969538e6b98170a8e0e445087526b87805d436621d936be9a7d7de87d34f4eae65ffbb3e91bea63fc7549bcbbd25c554
data/bin/ny_forecast CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'ny_forecast'
2
+ require_relative "../config/environment.rb"
3
3
 
4
- puts NYForecast.new
4
+ Runner.new.interface
@@ -0,0 +1,5 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ require_relative '../lib/find_forecast.rb'
5
+ require_relative '../lib/runner.rb'
@@ -0,0 +1,43 @@
1
+ require_relative '../config/environment.rb'
2
+
3
+ class FindForecast
4
+ def initialize(hour)
5
+ @first_six = Nokogiri::HTML(open("http://www.weather.com/weather/hourbyhour/graph/New+York+NY+USNY0996:1:US"))
6
+ @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)
10
+ end
11
+
12
+ def intro(hour)
13
+ introduction = "\nToday's date: #{Date.today}.\nThe weather for the next #{hour} hours is as follows:\n\n"
14
+ puts introduction
15
+ end
16
+
17
+ def scrape_forecast(hour)
18
+ scrape_six
19
+ scrape_eighteen if hour == 24
20
+ end
21
+
22
+ def scrape_six
23
+ to_delete = @first_six.css("span.wx-date-label").collect {|x| x.text} + @first_six.css("span.wx-day-label").collect {|x| x.text}
24
+ forecasts = @first_six.css("div.wx-timepart").collect { |section| section.text.gsub(/\n/,'') }
25
+ forecasts.each_with_index do |forecast, i|
26
+ to_delete.each do |word|
27
+ forecast.gsub!("#{word}", "")
28
+ end
29
+ 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
30
+ end
31
+ end
32
+
33
+ def scrape_eighteen
34
+ 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
+ forecasts = @next_eighteen.css("div.wx-timepart").collect { |section| section.text.gsub(/\n/,'') }
36
+ forecasts.each_with_index do |forecast, i|
37
+ to_delete.each do |word|
38
+ forecast.gsub!("#{word}", "")
39
+ end
40
+ 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
+ end
42
+ end
43
+ end
data/lib/runner.rb ADDED
@@ -0,0 +1,33 @@
1
+ require_relative '../config/environment.rb'
2
+
3
+ class Runner
4
+ def interface
5
+ on = true
6
+ puts "======================================="
7
+ puts "Welcome to NY Forecast"
8
+ puts
9
+ puts "You can view the hourly forecasts by entering '6' or '24' for 6-hour or 24-hour forecasts."
10
+ puts "(Type 'exit' to exit)"
11
+
12
+ while on do
13
+ @user_command = gets.chomp
14
+
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."
21
+ elsif @user_command == "exit"
22
+ exit
23
+ on = false
24
+ else
25
+ puts "Invalid request! Please enter '6' or '24' to view the 6-hour or 24-hour forecasts."
26
+ end
27
+ end
28
+ end
29
+
30
+ def exit
31
+ puts "Thanks for using NY Forecast"
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ny_forecast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Kohlbrenner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-01 00:00:00.000000000 Z
11
+ date: 2014-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: Gathers next-6-hour weather forecast for NYC from weather.com
27
+ description: Gathers 6- and 24-hour weather forecasts for NYC from weather.com
28
28
  email: chris.kohlbrenner@gmail.com
29
29
  executables:
30
30
  - ny_forecast
@@ -32,7 +32,9 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - bin/ny_forecast
35
- - lib/ny_forecast.rb
35
+ - config/environment.rb
36
+ - lib/find_forecast.rb
37
+ - lib/runner.rb
36
38
  homepage: http://rubygems.org/gems/ny_forecast
37
39
  licenses:
38
40
  - MIT
data/lib/ny_forecast.rb DELETED
@@ -1,29 +0,0 @@
1
- require 'nokogiri'
2
- require 'open-uri'
3
-
4
- class NYForecast
5
- def initialize
6
- @doc = Nokogiri::HTML(open("http://www.weather.com/weather/hourbyhour/graph/New+York+NY+USNY0996:1:US"))
7
- intro
8
- scrape_forecast
9
- end
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
15
-
16
- def scrape_forecast
17
- to_delete = @doc.css("span.wx-date-label").collect {|x| x.text} + @doc.css("span.wx-day-label").collect {|x| x.text}
18
-
19
- forecasts = @doc.css("div.wx-timepart").collect { |section| section.text.gsub(/\n/,'') }
20
-
21
- forecasts.each_with_index do |forecast, i|
22
- to_delete.each do |word|
23
- forecast.gsub!("#{word}", "")
24
- end
25
-
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
28
- end
29
- end