simple_forecast 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/bin/forecast +15 -0
- data/bin/run.rb +9 -0
- data/config/cli.rb +50 -0
- data/config/environment.rb +9 -0
- data/data/forecast_io_sample.rb +912 -0
- data/lib/models/forecast.rb +25 -0
- data/lib/models/scraper.rb +20 -0
- data/lib/weather_data.rb +34 -0
- data/notes.md +168 -0
- data/simple_forecast.gemspec +19 -0
- data/spec/cli_spec.rb +17 -0
- data/spec/geo_locate_spec.rb +3 -0
- data/spec/scraper_spec.rb +12 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/weather_data_spec.rb +9 -0
- data/spec/weather_report_spec.rb +3 -0
- metadata +82 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
class Forecast
|
2
|
+
|
3
|
+
attr_accessor :today_temp, :yesterday_temp
|
4
|
+
|
5
|
+
def initialize(weather_data_object)
|
6
|
+
|
7
|
+
@today_temp = weather_data_object.get_temp_today
|
8
|
+
@yesterday_temp = weather_data_object.get_temp_yesterday
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate_forecast
|
12
|
+
# determine whether today temp is higher, lower or the same as yesterday
|
13
|
+
# return a string based on that result
|
14
|
+
if self.today_temp == self.yesterday_temp
|
15
|
+
"same as yesterday"
|
16
|
+
elsif self.today_temp < self.yesterday_temp
|
17
|
+
"colder than yesterday"
|
18
|
+
else
|
19
|
+
"warmer than yesterday"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Scraper
|
2
|
+
attr_reader :forecast
|
3
|
+
|
4
|
+
def initialize(scrape_target)
|
5
|
+
@scraped_content = Nokogiri::HTML(open(scrape_target))
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_temp_yesterday
|
9
|
+
@scraped_content.css('p.wx-temp').text.strip[0..1].to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_temp_now
|
13
|
+
@scraped_content.css('span.temperature-fahrenheit')
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_temp_tomorrow
|
17
|
+
@scraped_content.css('p.wx-temp').text.strip[0..1].to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/weather_data.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
class WeatherData
|
2
|
+
|
3
|
+
attr_accessor :yesterday_data, :today_data
|
4
|
+
|
5
|
+
NYC_LAT = 40.714623
|
6
|
+
NYC_LON = -74.006605
|
7
|
+
|
8
|
+
def initialize(lat = NYC_LAT, lon = NYC_LON)
|
9
|
+
print "checking the weather."
|
10
|
+
@today_data = ForecastIO.forecast(lat, lon, time: Time.now.to_i)
|
11
|
+
print " . "
|
12
|
+
@yesterday_data = ForecastIO.forecast(lat, lon, time: time_yesterday)
|
13
|
+
print ".\n "
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
def time_yesterday
|
20
|
+
Time.now.to_i - 86400
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def get_temp_yesterday
|
25
|
+
self.yesterday_data["currently"]["temperature"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_temp_today
|
29
|
+
self.today_data["currently"]["temperature"]
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
end
|
data/notes.md
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
# # time
|
2
|
+
# Time.now.utc
|
3
|
+
|
4
|
+
# # cron job use whenever gem
|
5
|
+
# # apple uses launchd instead - works while computer is sleeping
|
6
|
+
|
7
|
+
# every 24.hours do
|
8
|
+
# #get weather forecast and store
|
9
|
+
# end
|
10
|
+
|
11
|
+
|
12
|
+
get temperatures for yesterday, today and tomorrow
|
13
|
+
just for new york, ny
|
14
|
+
allowing for invoking from the command line
|
15
|
+
|
16
|
+
# scraper = Scraper.new('http://students.flatironschool.com')
|
17
|
+
# scraper.get_links_to_student_pages
|
18
|
+
|
19
|
+
#TODO
|
20
|
+
# next: create a bunch of dummy data I can use to create a good command line
|
21
|
+
|
22
|
+
|
23
|
+
# class SimpleWeather
|
24
|
+
# def initialize(woeid)
|
25
|
+
# @weather = Weather.lookup(woeid, :fahrenheit)
|
26
|
+
# end
|
27
|
+
|
28
|
+
# def title
|
29
|
+
# @weather.title
|
30
|
+
# end
|
31
|
+
|
32
|
+
# def condition
|
33
|
+
# @weather.title
|
34
|
+
# end
|
35
|
+
|
36
|
+
# end
|
37
|
+
|
38
|
+
# my_weather = SimpleWeather.new(2459115)
|
39
|
+
|
40
|
+
|
41
|
+
# print <<-EOT
|
42
|
+
# #{response.title}
|
43
|
+
# #{response.condition.temp} degrees
|
44
|
+
# #{response.condition.text}
|
45
|
+
# EOT
|
46
|
+
|
47
|
+
|
48
|
+
# -> forecast for tomorrow
|
49
|
+
# -> slightly colder than yesterday
|
50
|
+
|
51
|
+
# -> forecast for seattle wa
|
52
|
+
# -> much colder than here, and rainier
|
53
|
+
|
54
|
+
### ARCHIVE
|
55
|
+
# def crawl_student_pages(student_page)
|
56
|
+
# url = Nokogiri::HTML(open(student_page))
|
57
|
+
# end
|
58
|
+
|
59
|
+
# def get_student_list
|
60
|
+
# students_list = @scraped_content.css('.home-blog ul')
|
61
|
+
# student_list_item = students_list.css('.blog-thumb a')
|
62
|
+
# end
|
63
|
+
|
64
|
+
# def get_student_images
|
65
|
+
# image = url.css('.student_pic').first.attributes["src"].value || "image"
|
66
|
+
# # student_images = @scraped_content.css('.home-blog .blog-thumb .prof-image')
|
67
|
+
# end
|
68
|
+
|
69
|
+
# def get_student_names
|
70
|
+
# name = @url.css('.ib_main_header').children[0].text || "name"
|
71
|
+
# # student_names = @scraped_content.css('.home-blog .blog-title .big-comment h3 a').text
|
72
|
+
# end
|
73
|
+
|
74
|
+
# def get_links_to_student_pages
|
75
|
+
# student_page_links = @scraped_content.css('.blog-thumb a').collect do |link|
|
76
|
+
# "http://students.flatironschool.com/" + link["href"]
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
|
80
|
+
# def get_student_quotes
|
81
|
+
# quote = url.css('.textwidget h3')[0].children.text.strip || "quote"
|
82
|
+
# end
|
83
|
+
|
84
|
+
# def get_student_cities
|
85
|
+
# cities = url.css('h3')[-3].parent.parent.children[5].children.map { |city| city.text.strip || "cities" }.reject(&:empty?)
|
86
|
+
# end
|
87
|
+
|
88
|
+
# def get_student_bios
|
89
|
+
# bio = url.css('h3')[1].parent.parent.children[5].text.strip || "bio"
|
90
|
+
# end
|
91
|
+
|
92
|
+
# def get_student_personal_projects
|
93
|
+
# personal_projects = url.css('h3')[-4].parent.parent.children[5].text.strip || "projects"
|
94
|
+
# end
|
95
|
+
|
96
|
+
# def get_coder_cred
|
97
|
+
# url.css(".coder-cred a").each do |instance|
|
98
|
+
# social_media_array << instance.attributes["href"].value
|
99
|
+
# end
|
100
|
+
# end
|
101
|
+
|
102
|
+
# def get_coder_cred
|
103
|
+
# url.css(".social-icons a").each do |link|
|
104
|
+
# social_media_array << link.attributes["href"].value
|
105
|
+
# end
|
106
|
+
# end
|
107
|
+
|
108
|
+
# def get_social_media
|
109
|
+
# social_media_array = social_media_array.uniq || "social media"
|
110
|
+
# end
|
111
|
+
|
112
|
+
# def add_to_db
|
113
|
+
# db = SQLite3::Database.new( "test.db" )
|
114
|
+
# db.execute(" create table if not exists student (
|
115
|
+
# student_name varchar2(30),
|
116
|
+
# image varchar2(30),
|
117
|
+
# quote text,
|
118
|
+
# biography text
|
119
|
+
# )
|
120
|
+
# ;")
|
121
|
+
|
122
|
+
# db.execute( "insert into student values ( ?, ?,?,? )",
|
123
|
+
# *student_name,*image,*quote, *biography )
|
124
|
+
# end
|
125
|
+
|
126
|
+
# # weather = Scraper.new('http://www.weather.com/weather/pastweather/hourly/USNY0996')
|
127
|
+
|
128
|
+
# # puts weather.yesterday
|
129
|
+
|
130
|
+
# forecast = Forecast.new(40.70536,74.013963)
|
131
|
+
|
132
|
+
#binding.pry
|
133
|
+
|
134
|
+
|
135
|
+
# forecast tomorrow
|
136
|
+
# compare tomorrow
|
137
|
+
# example: today = 64, tomorrow = 72 => a bit warmer than today
|
138
|
+
|
139
|
+
# command == "tomorrow"
|
140
|
+
# 1. if if tomorrow == today => "same as today"
|
141
|
+
# 2. if tomorrow > today => "warmer than today"
|
142
|
+
# 3. if tomorrow < today => "colder than today"
|
143
|
+
|
144
|
+
# 4. get the difference size value.
|
145
|
+
# 5. if the difference size value is < 3: "a smidge colder/warmer"
|
146
|
+
# 6. if between 3 and 8: a bit colder
|
147
|
+
# 7. if between 8 and 12 a lot colder
|
148
|
+
# 8. if greater than 12: way colder than today
|
149
|
+
|
150
|
+
# if not understand: "I have no idea what you just said, but I'm sure the forecast is excellent" or "Sorry, I didn't understand that."
|
151
|
+
|
152
|
+
# def get_forecast
|
153
|
+
# if @tomorrow == @today
|
154
|
+
# "same as today"
|
155
|
+
# elsif @tomorrow > @today
|
156
|
+
|
157
|
+
|
158
|
+
# end
|
159
|
+
|
160
|
+
# it "can return a mock reply to a weather forecast request" do
|
161
|
+
# @cli.command("forecast for tomorrow")
|
162
|
+
# @cli.command.should eq "a little warmer than today"
|
163
|
+
# end
|
164
|
+
|
165
|
+
# it "exits after providing a weather forecast" do
|
166
|
+
# @cli.command("exit")
|
167
|
+
# @cli.on.should eq false
|
168
|
+
# end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'simple_forecast'
|
3
|
+
s.executables << 'forecast'
|
4
|
+
s.version = "0.0.1"
|
5
|
+
s.date = "2013-10-19"
|
6
|
+
s.summary = "A simple weather forecaster"
|
7
|
+
s.description = "A simple weather forecaster"
|
8
|
+
s.authors = ["Anders Ramsay", "Joe O'Conor"]
|
9
|
+
s.email = ["andersr@gmail.com", "joe.oconor@gmail.com"]
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.homepage = 'https://github.com/andersr/simple_weather'
|
12
|
+
s.license = 'MIT'
|
13
|
+
s.require_path = '.'
|
14
|
+
s.add_runtime_dependency 'forecast_io' >= '2.0.0'
|
15
|
+
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
|
+
MSG
|
18
|
+
|
19
|
+
end
|
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative '../config/environment.rb'
|
2
|
+
|
3
|
+
describe "command line interface for the weather app" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@cli = CLI.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can be initialized" do
|
10
|
+
@cli.on?.should eq true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can accept a forecast command with no attributes"
|
14
|
+
|
15
|
+
it "can accept a forecast command with no attributes"
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
describe "getting weather data" do
|
2
|
+
|
3
|
+
it "can collect data from a website"
|
4
|
+
|
5
|
+
it "can collect the temperature forecast for tomorrow"
|
6
|
+
|
7
|
+
it "can collect the forecast for a specific location"
|
8
|
+
|
9
|
+
it "can collect the temperature for today"
|
10
|
+
|
11
|
+
it "can collect the temperature for yesterday"
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_forecast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anders Ramsay
|
8
|
+
- Joe O'Conor
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: 'true'
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
description: A simple weather forecaster
|
29
|
+
email:
|
30
|
+
- andersr@gmail.com
|
31
|
+
- joe.oconor@gmail.com
|
32
|
+
executables:
|
33
|
+
- forecast
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rspec
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- bin/forecast
|
42
|
+
- bin/run.rb
|
43
|
+
- config/cli.rb
|
44
|
+
- config/environment.rb
|
45
|
+
- data/forecast_io_sample.rb
|
46
|
+
- lib/models/forecast.rb
|
47
|
+
- lib/models/scraper.rb
|
48
|
+
- lib/weather_data.rb
|
49
|
+
- notes.md
|
50
|
+
- simple_forecast.gemspec
|
51
|
+
- spec/cli_spec.rb
|
52
|
+
- spec/geo_locate_spec.rb
|
53
|
+
- spec/scraper_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
- spec/weather_data_spec.rb
|
56
|
+
- spec/weather_report_spec.rb
|
57
|
+
homepage: https://github.com/andersr/simple_weather
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message: |2
|
62
|
+
Thanks for installing Simple Forecast. Enter 'forecast' to get the current forecast or something like 'forecast tomorrow' for a different forecast.
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- .
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.1.9
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: A simple weather forecaster
|
82
|
+
test_files: []
|