weather_usa 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +2 -0
- data/bin/console +15 -0
- data/bin/setup +7 -0
- data/bin/weather_usa +6 -0
- data/flowchart.pdf +0 -0
- data/lib/weather_usa.rb +18 -0
- data/lib/weather_usa/cli.rb +185 -0
- data/lib/weather_usa/geocode.rb +25 -0
- data/lib/weather_usa/scraper.rb +53 -0
- data/lib/weather_usa/version.rb +3 -0
- data/lib/weather_usa/weather.rb +22 -0
- data/weather_usa.gemspec +33 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f6c3b86625407a23251757879aa5751cf17315820ae781d9974ccd50a88e227b
|
4
|
+
data.tar.gz: 35d54d72f74778ee487562ff5e4e806ddd772e4d31707d898452e0557f44cf9c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e3e17cb66d094eec50dbf854031874eef1d934f9f860ca50042d15b76e189d5a89c828991d9966f46f6a6d97f206f3607a25fe61fda2c00fd1c86eac63ab762b
|
7
|
+
data.tar.gz: c8d7f0f7d8c21d54bbda724a45a966a612aecb36c25b2d83e8a2e96d0c3ac7ab951f5f87a66b54fa381ec35f0dc4dafd4aef36366621888ec25e74e059d00392
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at micahmccallum@outlook.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
weather_usa (0.1.0)
|
5
|
+
colorize (~> 0.8.0)
|
6
|
+
geocoder (~> 1.6.0)
|
7
|
+
json-ld (~> 3.1.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
coderay (1.1.2)
|
13
|
+
colorize (0.8.1)
|
14
|
+
concurrent-ruby (1.1.6)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
geocoder (1.6.3)
|
17
|
+
hamster (3.0.0)
|
18
|
+
concurrent-ruby (~> 1.0)
|
19
|
+
htmlentities (4.3.4)
|
20
|
+
json-canonicalization (0.2.0)
|
21
|
+
json-ld (3.1.4)
|
22
|
+
htmlentities (~> 4.3)
|
23
|
+
json-canonicalization (~> 0.2)
|
24
|
+
link_header (~> 0.0, >= 0.0.8)
|
25
|
+
multi_json (~> 1.14)
|
26
|
+
rack (~> 2.0)
|
27
|
+
rdf (~> 3.1)
|
28
|
+
link_header (0.0.8)
|
29
|
+
method_source (1.0.0)
|
30
|
+
multi_json (1.14.1)
|
31
|
+
pry (0.13.1)
|
32
|
+
coderay (~> 1.1)
|
33
|
+
method_source (~> 1.0)
|
34
|
+
rack (2.2.2)
|
35
|
+
rake (12.3.3)
|
36
|
+
rdf (3.1.1)
|
37
|
+
hamster (~> 3.0)
|
38
|
+
link_header (~> 0.0, >= 0.0.8)
|
39
|
+
rspec (3.9.0)
|
40
|
+
rspec-core (~> 3.9.0)
|
41
|
+
rspec-expectations (~> 3.9.0)
|
42
|
+
rspec-mocks (~> 3.9.0)
|
43
|
+
rspec-core (3.9.2)
|
44
|
+
rspec-support (~> 3.9.3)
|
45
|
+
rspec-expectations (3.9.1)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.9.0)
|
48
|
+
rspec-mocks (3.9.1)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.9.0)
|
51
|
+
rspec-support (3.9.3)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
pry (~> 0.13.0)
|
58
|
+
rake (~> 12.0)
|
59
|
+
rspec (~> 3.9.0)
|
60
|
+
weather_usa!
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Micah McCallum
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# WeatherUsa
|
2
|
+
|
3
|
+
WeatherUsa is a gem that with a zip code or a city and state combination returns the weather information from the weather.gov API for the United States of America and displays the formatted information to the console. After the initial search, current conditions are shown, along with any weather alerts. There are also options for seeing more detailed forecasts or searching for another location. Try it out!
|
4
|
+
Please note: At times there are issues with the API servers' response and at this time I have not included any way to handle these. This will be looked at in a future release.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'weather_usa'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install weather_usa
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
From the command-line just type
|
25
|
+
|
26
|
+
$ weather_usa
|
27
|
+
|
28
|
+
to start the program.
|
29
|
+
|
30
|
+
After starting the program, just follow the onscreen menu; it is very self-guided.
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/weather_usa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/weather_usa/blob/master/CODE_OF_CONDUCT.md).
|
41
|
+
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
46
|
+
|
47
|
+
## Code of Conduct
|
48
|
+
|
49
|
+
Everyone interacting in the WeatherUsa project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/weather_usa/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "weather_usa"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
15
|
+
|
data/bin/setup
ADDED
data/bin/weather_usa
ADDED
data/flowchart.pdf
ADDED
Binary file
|
data/lib/weather_usa.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "geocoder"
|
2
|
+
require "open-uri"
|
3
|
+
require "json/ld"
|
4
|
+
require "colorize"
|
5
|
+
|
6
|
+
require "weather_usa/version"
|
7
|
+
require "weather_usa/cli"
|
8
|
+
require "weather_usa/scraper"
|
9
|
+
require "weather_usa/weather"
|
10
|
+
require "weather_usa/geocode"
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
module WeatherUsa
|
16
|
+
class Error < StandardError; end
|
17
|
+
# Your code goes here...
|
18
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
class WeatherUsa::CLI
|
2
|
+
|
3
|
+
BASE_PATH = "https://api.weather.gov/"
|
4
|
+
|
5
|
+
def call
|
6
|
+
system "clear"
|
7
|
+
self.greeting
|
8
|
+
self.new_location
|
9
|
+
end
|
10
|
+
|
11
|
+
def new_location
|
12
|
+
Weather.clear_all
|
13
|
+
self.ask_for_new_location
|
14
|
+
@input = gets.strip
|
15
|
+
self.get_weather_information
|
16
|
+
system "clear"
|
17
|
+
self.display_current_conditions
|
18
|
+
self.display_alert
|
19
|
+
self.options
|
20
|
+
end
|
21
|
+
|
22
|
+
def greeting
|
23
|
+
puts
|
24
|
+
puts
|
25
|
+
puts " *** Welcome to Weather USA! ***".blue
|
26
|
+
end
|
27
|
+
|
28
|
+
def ask_for_new_location
|
29
|
+
puts
|
30
|
+
puts " Please enter a geographic location in the United States.".blue
|
31
|
+
puts " (This can be a zip code or a city and state)".blue
|
32
|
+
puts
|
33
|
+
print " >> ".green
|
34
|
+
end
|
35
|
+
|
36
|
+
def goodbye
|
37
|
+
puts
|
38
|
+
puts
|
39
|
+
puts " *** Thank you for using Weather USA. ***".blue
|
40
|
+
puts
|
41
|
+
puts
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
|
45
|
+
def options
|
46
|
+
puts
|
47
|
+
puts " What would you like to do? (Please select an option.)".blue
|
48
|
+
puts
|
49
|
+
puts " 1) See a detailed forecast for the current location.".blue
|
50
|
+
puts
|
51
|
+
puts " 2) See an extended forecast.".blue
|
52
|
+
puts
|
53
|
+
puts " 3) Choose a different location.".blue
|
54
|
+
puts
|
55
|
+
puts " 4) Exit the program.".blue
|
56
|
+
puts
|
57
|
+
print " >> ".green
|
58
|
+
option = gets.strip.to_s
|
59
|
+
system "clear"
|
60
|
+
case option
|
61
|
+
when "1"
|
62
|
+
self.display_detailed_forecast
|
63
|
+
self.options
|
64
|
+
when "2"
|
65
|
+
self.display_extended_forecast
|
66
|
+
self.options
|
67
|
+
when "3"
|
68
|
+
self.new_location
|
69
|
+
when "4"
|
70
|
+
self.goodbye
|
71
|
+
else
|
72
|
+
self.options
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def display_current_conditions
|
77
|
+
right_now = self.current_conditions
|
78
|
+
right_now.current[:wind_speed] != nil ? wind_speed = meters_to_miles(right_now.current[:wind_speed]).round(0) : wind_speed = "N/A"
|
79
|
+
right_now.current[:temperature] != nil ? temperature = to_fahr(right_now.current[:temperature]) : temperature = "N/A"
|
80
|
+
puts " Weather forecast for ".blue + "#{@location.name}".green + ":".blue
|
81
|
+
puts " Current observations at: ".blue + "#{right_now.current[:station_name]}".green + ",".blue
|
82
|
+
puts " the current temperature is ".blue + "#{temperature}".green + ",".blue
|
83
|
+
puts " the current wind speed is ".blue + "#{wind_speed} mph".green + " from the ".blue +
|
84
|
+
"#{wind_direction_from_degrees(right_now.current[:wind_direction])}".green + ".".blue
|
85
|
+
puts " Expected conditions: ".blue + "#{right_now.short_forecast}.".green
|
86
|
+
end
|
87
|
+
|
88
|
+
def display_alert
|
89
|
+
if current_conditions.current[:alert_headline]
|
90
|
+
puts " Current alert: ".red + "#{current_conditions.current[:alert_headline]}.".yellow
|
91
|
+
puts
|
92
|
+
puts " Do you want to see a detailed description of the alert? (y/n)".blue
|
93
|
+
puts
|
94
|
+
print " >> ".green
|
95
|
+
input = gets.strip.downcase
|
96
|
+
puts
|
97
|
+
if input == "y"
|
98
|
+
system "clear"
|
99
|
+
current_conditions.current[:alert_description].split("\n").each do |line|
|
100
|
+
puts " #{line}".yellow
|
101
|
+
end
|
102
|
+
puts
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def display_detailed_forecast
|
108
|
+
puts
|
109
|
+
puts
|
110
|
+
puts " Weather forecast for ".blue + "#{@location.name}".green + ":".blue
|
111
|
+
current_conditions.detailed_forecast.split(".").each do |line|
|
112
|
+
puts " #{line}.".green
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def display_extended_forecast
|
117
|
+
Weather.all.each_with_index do |period, index|
|
118
|
+
period.is_daytime ? am_pm = "High" : am_pm = "Low"
|
119
|
+
if index < 8
|
120
|
+
puts " #{period.name}".green
|
121
|
+
puts " #{period.short_forecast}".green
|
122
|
+
puts " #{am_pm} temperature: ".blue + "#{period.temperature}".green
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def get_weather_information
|
128
|
+
self.get_location
|
129
|
+
self.scrape_weather_site
|
130
|
+
self.create_weather_objects_from_array
|
131
|
+
end
|
132
|
+
|
133
|
+
def get_location
|
134
|
+
@location = Geocode.get_geocode(@input)
|
135
|
+
end
|
136
|
+
|
137
|
+
def scrape_weather_site
|
138
|
+
@weather_array = Scraper.scrape_weather_dot_gov(BASE_PATH, @location)
|
139
|
+
end
|
140
|
+
|
141
|
+
def create_weather_objects_from_array
|
142
|
+
@weather_array.each do |period|
|
143
|
+
Weather.new(period)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def current_conditions
|
148
|
+
Weather.all[0]
|
149
|
+
end
|
150
|
+
|
151
|
+
def to_fahr(number)
|
152
|
+
((number * 9) / 5 + 32).round(0)
|
153
|
+
end
|
154
|
+
|
155
|
+
def meters_to_miles(number)
|
156
|
+
(number * 2.23694).round(0)
|
157
|
+
end
|
158
|
+
|
159
|
+
def wind_direction_from_degrees(degrees)
|
160
|
+
case degrees
|
161
|
+
when 0..22.5
|
162
|
+
"N"
|
163
|
+
when 22.6..67.5
|
164
|
+
"NE"
|
165
|
+
when 67.6..112.5
|
166
|
+
"E"
|
167
|
+
when 112.6..157.5
|
168
|
+
"SE"
|
169
|
+
when 157.6..202.5
|
170
|
+
"S"
|
171
|
+
when 202.6..247.5
|
172
|
+
"SW"
|
173
|
+
when 247.6..292.5
|
174
|
+
"W"
|
175
|
+
when 292.6..337.5
|
176
|
+
"NW"
|
177
|
+
when 337.6..360
|
178
|
+
"N"
|
179
|
+
else
|
180
|
+
"N/A"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Geocode
|
2
|
+
attr_reader :latitude, :longitude, :name
|
3
|
+
|
4
|
+
def initialize(result)
|
5
|
+
location = result.find {|obj| obj.data["address"]["country_code"] == "us"}
|
6
|
+
@name = location.data["display_name"]
|
7
|
+
@latitude = location.data["lat"]
|
8
|
+
@longitude = location.data["lon"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.get_geocode(search_term)
|
12
|
+
result = Geocoder.search(search_term)
|
13
|
+
if !(result.find {|obj| obj.data["address"]["country_code"] == "us"})
|
14
|
+
puts
|
15
|
+
puts " Please enter a valid search.".red
|
16
|
+
puts
|
17
|
+
print " >> ".green
|
18
|
+
input = gets.strip
|
19
|
+
self.get_geocode(input)
|
20
|
+
else
|
21
|
+
Geocode.new(result)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
class Scraper
|
3
|
+
|
4
|
+
def self.scrape_weather_dot_gov(url, location)
|
5
|
+
|
6
|
+
weather_array = []
|
7
|
+
current = {}
|
8
|
+
base_url = url + "points/#{location.latitude},#{location.longitude}"
|
9
|
+
station_url = base_url + "/stations"
|
10
|
+
forecast_url = base_url + "/forecast"
|
11
|
+
station_doc = Scraper::get_doc(station_url)
|
12
|
+
station_id = station_doc["features"].first["properties"]["stationIdentifier"]
|
13
|
+
station_name = station_doc["features"].first["properties"]["name"]
|
14
|
+
current_url = url + "stations/#{station_id}/observations/latest"
|
15
|
+
current_doc = Scraper::get_doc(current_url)
|
16
|
+
current[:weather_description] = current_doc["properties"]["textDescription"]
|
17
|
+
current[:temperature] = current_doc["properties"]["temperature"]["value"]
|
18
|
+
current[:wind_speed] = current_doc["properties"]["windSpeed"]["value"]
|
19
|
+
current[:wind_direction] = current_doc["properties"]["windDirection"]["value"]
|
20
|
+
current[:station_name] = station_name
|
21
|
+
zone_doc = Scraper::get_doc(base_url)
|
22
|
+
zone_id = zone_doc["properties"]["forecastZone"].split("/").last
|
23
|
+
alert_url = url + "alerts/active/zone/#{zone_id}"
|
24
|
+
alerts = Scraper::get_doc(alert_url)
|
25
|
+
|
26
|
+
if alerts["features"].count > 0
|
27
|
+
current[:alert_headline] = alerts["features"][0]["properties"]["headline"]
|
28
|
+
current[:alert_description] = alerts["features"][0]["properties"]["description"]
|
29
|
+
end
|
30
|
+
|
31
|
+
forecast_doc = Scraper::get_doc(forecast_url)
|
32
|
+
periods = forecast_doc["properties"]["periods"]
|
33
|
+
periods.each do |period|
|
34
|
+
weather_period = {}
|
35
|
+
weather_period[:number] = period["number"]
|
36
|
+
weather_period[:name] = period["name"]
|
37
|
+
weather_period[:temperature] = period["temperature"]
|
38
|
+
weather_period[:wind_speed] = period["windSpeed"]
|
39
|
+
weather_period[:wind_direction] = period["windDirection"]
|
40
|
+
weather_period[:short_forecast] = period["shortForecast"]
|
41
|
+
weather_period[:detailed_forecast] = period["detailedForecast"]
|
42
|
+
weather_period[:is_daytime] = period["isDaytime"]
|
43
|
+
weather_array << weather_period
|
44
|
+
end
|
45
|
+
weather_array[0][:current] = current
|
46
|
+
weather_array
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.get_doc(url)
|
50
|
+
JSON.load(URI.open(url))
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Weather
|
2
|
+
attr_accessor :number, :name, :temperature, :wind_speed, :wind_direction,
|
3
|
+
:short_forecast, :detailed_forecast, :current, :is_daytime
|
4
|
+
|
5
|
+
@@all = []
|
6
|
+
|
7
|
+
def initialize(weather_hash)
|
8
|
+
weather_hash.each do |k, v|
|
9
|
+
self.send "#{k}=", v
|
10
|
+
end
|
11
|
+
@@all << self
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.all
|
15
|
+
@@all
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.clear_all
|
19
|
+
@@all = []
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/weather_usa.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'lib/weather_usa/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "weather_usa"
|
5
|
+
spec.version = WeatherUsa::VERSION
|
6
|
+
spec.authors = ["Micah McCallum"]
|
7
|
+
spec.email = ["micahmccallum@outlook.com"]
|
8
|
+
|
9
|
+
spec.summary = "A gem to pull weather information from weather.gov"
|
10
|
+
spec.homepage = "https://github.com/micahmccallum/weather_usa.git"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/micahmccallum/weather_usa.git"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/micahmccallum/weather_usa.git"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "bin"
|
27
|
+
spec.executables = ["weather_usa"]
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "geocoder", "~> 1.6.0"
|
31
|
+
spec.add_dependency "json-ld", "~> 3.1.0"
|
32
|
+
spec.add_dependency "colorize", "~> 0.8.0"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: weather_usa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Micah McCallum
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: geocoder
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json-ld
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.8.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.0
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- micahmccallum@outlook.com
|
58
|
+
executables:
|
59
|
+
- weather_usa
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- bin/weather_usa
|
73
|
+
- flowchart.pdf
|
74
|
+
- lib/weather_usa.rb
|
75
|
+
- lib/weather_usa/cli.rb
|
76
|
+
- lib/weather_usa/geocode.rb
|
77
|
+
- lib/weather_usa/scraper.rb
|
78
|
+
- lib/weather_usa/version.rb
|
79
|
+
- lib/weather_usa/weather.rb
|
80
|
+
- weather_usa.gemspec
|
81
|
+
homepage: https://github.com/micahmccallum/weather_usa.git
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata:
|
85
|
+
homepage_uri: https://github.com/micahmccallum/weather_usa.git
|
86
|
+
source_code_uri: https://github.com/micahmccallum/weather_usa.git
|
87
|
+
changelog_uri: https://github.com/micahmccallum/weather_usa.git
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.3.0
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubygems_version: 3.1.2
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: A gem to pull weather information from weather.gov
|
107
|
+
test_files: []
|