simple_forecast 0.0.2 → 0.0.3.1

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: a55167aba9bc0078e3ca220ca45251b5e141e04b
4
- data.tar.gz: 9453f1260b7b6be4783c1aabe2b90a6f51ad90e4
3
+ metadata.gz: ceb60046f195e4e07230cd783255fa77f01fb6c9
4
+ data.tar.gz: 6b994bd43ec0be2c3c58a810527be4ef96358e13
5
5
  SHA512:
6
- metadata.gz: d78b42052ff134d30a0ff8d8ac8cf716f624526f7db29505cedf856caf28ebf2ad6d3fb884e8d6d5e99abe337c40272d3e0a0d8f642c8e82a5b2cde7cb20145a
7
- data.tar.gz: 67797b201fcb5b82da75532b3c944f3f98b86f94f65ce997f7652330fe53cf70fa0826581c2728191c7b3a64abb7e524c15b44159ddf221143b74fba3181fb17
6
+ metadata.gz: 7ac73c3629ee0265f83d006dcdc8d8846a18c0bfd54489f389782bfa440c999b0e91af902dc4a86339183035bc1df5903eaf4af2b250e568f842d070bae67c53
7
+ data.tar.gz: 1b27160d13f9618cd15552b43098fb48489008c8a024f22e25fb66a91b11e8f38c0f55ed1c24322fd3d63a401f21c3b38e3671271998f9068e65f2f6b475a743
data/.gitignore CHANGED
@@ -16,3 +16,5 @@ tmp
16
16
  .yardoc
17
17
  _yardoc
18
18
  doc/
19
+
20
+ reference/
@@ -1,14 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- # require 'simple_forecast'
4
-
5
2
  require_relative '../config/environment.rb'
6
-
7
3
  cli = CLIRouter.new(ARGV)
8
-
9
- # if ARGV.empty?
10
- # # this should return the same as 'forecast today'
11
- # ARGV[0] = "help"
12
- # end
13
-
14
- cli.commands
4
+ #cli.parse_commands
@@ -1,10 +1,12 @@
1
1
  require 'forecast_io'
2
- #require 'pry'
2
+ require 'geocoder'
3
+ require 'open-uri'
4
+
5
+ # TODO: set this gem to only be used in dev
6
+ require 'pry'
3
7
 
4
8
  ForecastIO.api_key = '2b5cab93f5051c1207517df51d39ceee'
5
9
 
6
- require_relative '../config/cli'
7
- require_relative '../lib/models/scraper'
8
10
  require_relative '../lib/models/forecast'
9
- require_relative '../lib/weather_data'
11
+ require_relative '../lib/models/weather_data'
10
12
  require_relative '../lib/models/cli_router'
@@ -1,33 +1,64 @@
1
1
  class CLIRouter
2
2
 
3
- attr_reader :weather_forecast, :args
3
+ attr_reader :weather_forecast, :commands
4
4
 
5
- def initialize(args)
6
- @weather_forecast = Forecast.new(WeatherData.new)
7
- @args = args # in fact this is ARGV
8
- end
5
+ APPROVED_COMMANDS = ["help","today","tomorrow","weekend"]
9
6
 
10
- def help
11
- weather_forecast.today
12
- puts "if you'd like a different forecast try something like 'forecast tomorrow'"
13
- end
7
+ def initialize(commands)
8
+ @commands = commands # in fact this is ARGV
14
9
 
15
- def commands
16
- if args.length == 1
17
- puts weather_forecast.send(self.args[0])
18
- elsif args.length == 0
10
+ if commands.length == 0
11
+ puts "Please enter something like 'forecast tomorrow' or enter 'forecast help' to learn more."
12
+ elsif commands.include?("help")
19
13
  help
14
+ else
15
+ parse_commands
20
16
  end
21
17
  end
18
+
19
+ def collect_weather_data
20
+ get_user_location
21
+ set_forecast_location
22
+ wd = WeatherData.new(@forecast_location.first, @forecast_location.last)
23
+ @weather_forecast = Forecast.new(wd)
24
+ end
22
25
 
23
- # def this_weekend
24
- # puts weather_data.this_weekend
26
+ def get_user_location
27
+ @longitude_latitude = Geocoder.coordinates(open('http://whatismyip.akamai.com').read)
28
+ end
29
+
30
+ def set_forecast_location
31
+ #based on idea that location would live in second slot
25
32
 
26
- # end
33
+ #if other location false, use current location
34
+ @forecast_location = Geocoder.coordinates(commands[1]) || @longitude_latitude
35
+ end
27
36
 
28
- # def next_week
29
- # puts weather_data.next_week
30
- # end
37
+ def help
38
+ # TODO: rewrite with more detailed help block
39
+ #puts weather_forecast.today
40
+ #puts weather_forecast.separator
41
+ puts <<-TEXT
42
+
43
+ Thanks for using Simple Forecast. Currently, the following commands are supported:
44
+
45
+ help Displays help (what you're viewing now)
46
+ today Today's forecast (compared to yesterday)
47
+ tomorrow Tomorrow's forecast (compared to today)
48
+ weekend Average temperature for this weekend (compared to today)
49
+
50
+ TEXT
51
+ end
52
+
53
+ def parse_commands
54
+ #binding.pry
55
+ if commands.length == 1 && APPROVED_COMMANDS.include?(commands[0])
56
+ collect_weather_data
57
+ puts weather_forecast.send(self.commands[0])
58
+ else
59
+ puts "Sorry, not sure what you're asking for, please enter 'forecast help' to learn more."
60
+ end
61
+ end
31
62
 
32
63
  end
33
64
 
@@ -1,47 +1,67 @@
1
1
  class Forecast
2
2
 
3
- attr_accessor :today_temp, :yesterday_temp, :tomorrow_temp, :weather_data
3
+ attr_accessor :today_temp, :yesterday_temp, :tomorrow_temp, :weather_data, :compare_loc
4
4
 
5
5
  def initialize(weather_data_object)
6
6
  @weather_data = weather_data_object
7
-
8
- @today_temp = self.weather_data.temp_today
9
- @tomorrow_temp = self.weather_data.temp_tomorrow
10
- # @this_weekend = self.avg_temp_this_weekend
11
- # @next_week = self.avg_temp_next_week
7
+ @today_temp = self.weather_data.today_temp
8
+ @tomorrow_temp = self.weather_data.tomorrow_temp
12
9
  end
13
10
 
14
11
  def today
15
- puts "hmm, interesting!"
16
- @yesterday_temp = self.weather_data.temp_yesterday
17
- compare(today_temp, yesterday_temp) + "yesterday"
12
+ @yesterday_temp = self.weather_data.yesterday_temp
13
+ separator +
14
+ "#{compare(today_temp, yesterday_temp)}yesterday, #{self.weather_data.today_summary}"
18
15
  end
19
16
 
20
17
  def tomorrow
21
- compare(tomorrow_temp, today_temp) + "today"
18
+ separator +
19
+ "#{compare(tomorrow_temp, today_temp)}today, #{self.weather_data.tomorrow_summary}"
20
+ end
21
+
22
+ def weekend
23
+ separator +
24
+ "this weekend will be " +
25
+ compare(avg_temp_this_weekend, today_temp) + "today"
22
26
  end
23
27
 
28
+ def next_week
29
+ # TODO: compare(this_week_avg, today)
30
+ end
31
+
24
32
  def avg_temp_this_weekend
33
+ data = find_weekend_data
34
+ weekend_avg = (data[0]["temperatureMax"] + data[1]["temperatureMax"])/2
35
+ end
25
36
 
37
+ def find_weekend_data
38
+ weekend_data = weather_data.today_data["daily"]["data"][1..7].select do |data_hash|
39
+ ruby_datetime = Time.at(data_hash["time"])
40
+ ruby_datetime.saturday? || ruby_datetime.sunday?
41
+ end
26
42
  end
27
43
 
28
- def avg_temp_next_weekend
44
+ def avg_temp_this_week
29
45
 
30
46
  end
31
47
 
32
- def this_weekend
33
- # compare(this_week_avg_temp?, temp_for_upcoming_weekend)
48
+ def avg_temp_next_week
34
49
  end
35
50
 
36
- def next_week
37
- # compare(this_week_avg, next_week_avg)
51
+ def find_week_time
52
+ week_data = weather_data.today_data["daily"]["data"][1..7].reject do |data_hash|
53
+ ruby_datetime = Time.at(data_hash["time"])
54
+ ruby_datetime.saturday? || ruby_datetime.sunday?
55
+ end
56
+ pp week_data
57
+ week_data
38
58
  end
39
59
 
40
60
  def compare(temp1, temp2)
41
- diff = temp1-temp2
61
+ diff = (temp1.round-temp2.round).abs
42
62
 
43
- case diff.abs
44
- when (1..2)
63
+ case diff
64
+ when (0..2)
45
65
  temp1 = temp2
46
66
  when (3..7)
47
67
  mod = "slightly "
@@ -54,7 +74,7 @@ class Forecast
54
74
  end
55
75
 
56
76
  if temp1 == temp2
57
- "pretty much the same as "
77
+ "about the same as "
58
78
  elsif temp1 < temp2
59
79
  mod + "colder than "
60
80
  else
@@ -62,15 +82,9 @@ class Forecast
62
82
  end
63
83
  end
64
84
 
65
- # categorization
66
- # "same"
67
- # "colder than"
68
- # "warmer than"
69
-
70
- # compared objects
71
- # "yesterday"
72
- # "today"
73
- # "tomorrow"
85
+ def separator
86
+ "\n"
87
+ end
74
88
 
75
89
  end
76
90
 
@@ -0,0 +1,43 @@
1
+ class WeatherData
2
+
3
+ attr_accessor :yesterday_data, :today_data, :lat, :long
4
+
5
+ NYC = [40.714623, -74.006605]
6
+ NYC_LAT = NYC[0]
7
+ NYC_LONG = NYC[1]
8
+
9
+ def initialize(lat = NYC.first, long = NYC.last)
10
+ @lat = lat
11
+ @long = long
12
+ print '.'
13
+ @today_data = ForecastIO.forecast(self.lat, self.long)
14
+ # when you don't specify a time in the ForecastIO call, you can get the daily high temps
15
+ end
16
+
17
+ def yesterday_temp
18
+ print '.'
19
+ @yesterday_data = ForecastIO.forecast(self.lat, self.long, time: time_yesterday)
20
+ self.yesterday_data["daily"]["data"].first["temperatureMax"]
21
+ end
22
+
23
+ def today_temp
24
+ self.today_data["daily"]["data"].first["temperatureMax"]
25
+ end
26
+
27
+ def today_summary
28
+ self.today_data["daily"]["data"][0]["summary"].downcase.gsub(/\./,'')
29
+ end
30
+
31
+ def tomorrow_temp
32
+ self.today_data["daily"]["data"][1]["temperatureMax"]
33
+ end
34
+
35
+ def tomorrow_summary
36
+ self.today_data["daily"]["data"][1]["summary"].downcase.gsub(/\./,'')
37
+ end
38
+
39
+ def time_yesterday
40
+ Time.now.to_i - 86400
41
+ end
42
+
43
+ end
@@ -1,19 +1,22 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'simple_forecast'
3
3
  s.executables << 'forecast'
4
- s.version = "0.0.2"
5
- s.date = "2013-10-19"
4
+ s.version = "0.0.3.1"
5
+ s.date = "2013-10-27"
6
6
  s.summary = "A simple weather forecaster"
7
- s.description = "A weather forecast relative to current conditions where you are. Currently only works for New York, NY."
7
+ s.description = "A weather forecast relative to current conditions where you are. Allows for getting the forecast for today, tomorrow, or the upcoming weekend."
8
8
  s.authors = ["Anders Ramsay", "Joe O'Conor"]
9
9
  s.email = ["andersr@gmail.com", "joe.oconor@gmail.com"]
10
10
  s.files = `git ls-files`.split("\n")
11
- s.homepage = 'https://github.com/andersr/simple_weather'
11
+ s.homepage = 'https://github.com/simple-forecast/ruby-gem'
12
12
  s.license = 'MIT'
13
13
  s.require_path = '.'
14
14
  s.add_runtime_dependency 'forecast_io', ['>= 2.0.0']
15
+ s.add_runtime_dependency 'geocoder', ['>= 1.1.8']
15
16
  s.post_install_message = <<-MSG
16
- Thanks for installing Simple Forecast. Enter 'forecast' to get the current forecast or something like 'forecast tomorrow' for a different forecast.
17
+
18
+ Thanks for installing Simple Forecast. Enter 'forecast today' to get today's forecast. Enter 'forecast help' for more commands.
19
+
17
20
  MSG
18
21
 
19
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_forecast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anders Ramsay
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-19 00:00:00.000000000 Z
12
+ date: 2013-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: forecast_io
@@ -25,8 +25,22 @@ dependencies:
25
25
  - - '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: 2.0.0
28
- description: A weather forecast relative to current conditions where you are. Currently
29
- only works for New York, NY.
28
+ - !ruby/object:Gem::Dependency
29
+ name: geocoder
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: 1.1.8
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.1.8
42
+ description: A weather forecast relative to current conditions where you are. Allows
43
+ for getting the forecast for today, tomorrow, or the upcoming weekend.
30
44
  email:
31
45
  - andersr@gmail.com
32
46
  - joe.oconor@gmail.com
@@ -40,15 +54,10 @@ files:
40
54
  - LICENSE
41
55
  - README.md
42
56
  - bin/forecast
43
- - bin/run.rb
44
- - config/cli.rb
45
57
  - config/environment.rb
46
- - data/forecast_io_sample.rb
47
58
  - lib/models/cli_router.rb
48
59
  - lib/models/forecast.rb
49
- - lib/models/scraper.rb
50
- - lib/weather_data.rb
51
- - notes.md
60
+ - lib/models/weather_data.rb
52
61
  - simple_forecast.gemspec
53
62
  - spec/cli_spec.rb
54
63
  - spec/geo_locate_spec.rb
@@ -56,12 +65,14 @@ files:
56
65
  - spec/spec_helper.rb
57
66
  - spec/weather_data_spec.rb
58
67
  - spec/weather_report_spec.rb
59
- homepage: https://github.com/andersr/simple_weather
68
+ homepage: https://github.com/simple-forecast/ruby-gem
60
69
  licenses:
61
70
  - MIT
62
71
  metadata: {}
63
- post_install_message: |2
64
- Thanks for installing Simple Forecast. Enter 'forecast' to get the current forecast or something like 'forecast tomorrow' for a different forecast.
72
+ post_install_message: |2+
73
+
74
+ Thanks for installing Simple Forecast. Enter 'forecast today' to get today's forecast. Enter 'forecast help' for more commands.
75
+
65
76
  rdoc_options: []
66
77
  require_paths:
67
78
  - .
data/bin/run.rb DELETED
@@ -1,9 +0,0 @@
1
- require_relative '../config/environment.rb'
2
-
3
- # weather = WeatherData.new
4
- # forecast = Forecast.new(weather)
5
- # forecast.generate_forecast
6
-
7
- CLI.new
8
-
9
- # binding.pry
@@ -1,56 +0,0 @@
1
- class CLI
2
-
3
- def initialize
4
- @on = true
5
- #self.call
6
- end
7
-
8
- def on?
9
- @on
10
- end
11
-
12
- def call
13
- while @on == true
14
- self.command
15
- end
16
- end
17
-
18
- def command
19
- input = command_request
20
- self.send(input)
21
- end
22
-
23
- def command_request
24
- gets.downcase.strip
25
- end
26
-
27
- ### COMMANDS ###
28
- # COMMANDS = {
29
- # :now => ["", "now", "today"],
30
- # :tonight => ["tonight"],
31
- # :tomorrow => ["tomorrow"],
32
- # :next_week => ["next week"]
33
- # :help => ["help"]
34
- # }
35
-
36
- def exit
37
- @on = false
38
- end
39
-
40
- def help
41
- puts "Please enter something like 'today' or 'tomorrow'."
42
- end
43
-
44
- def tomorrow
45
- get_data = Forecast.new(WeatherData.new)
46
- puts get_data.tomorrow
47
- # exit
48
- end
49
-
50
- def today
51
- get_data = Forecast.new(WeatherData.new)
52
- puts get_data.today
53
- end
54
-
55
-
56
- end