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 +4 -4
- data/bin/ny_forecast +2 -2
- data/config/environment.rb +5 -0
- data/lib/find_forecast.rb +43 -0
- data/lib/runner.rb +33 -0
- metadata +6 -4
- data/lib/ny_forecast.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 265c834c132adf9a24dbd6b2af51b5aabb94c57d
|
4
|
+
data.tar.gz: cfcb8dc03ce765a84893561e2574b78e4aa2e126
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe6dea451461aa3a03f5f7a9de13d4f78b5c22e8f0d7537fdcac724cbae360019e83b3e1f730c25219c847fc1930b6097c3a45d021ee85a8e27f274b9d6d5e43
|
7
|
+
data.tar.gz: 77bf24921ef2668ddcd23c3272ccdd1c969538e6b98170a8e0e445087526b87805d436621d936be9a7d7de87d34f4eae65ffbb3e91bea63fc7549bcbbd25c554
|
data/bin/ny_forecast
CHANGED
@@ -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.
|
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-
|
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
|
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
|
-
-
|
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
|