weather_alert_mbj 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9536c7dba0d236238ad5fb074dd698724df522f9a4e812254776c4f8281cbaeb
4
+ data.tar.gz: b119b746f99c87d23d50bb7fecaecc8b3e05b596a8c655fa84df53d3cba68630
5
+ SHA512:
6
+ metadata.gz: 8cf12ea369c56a235999204809f3b1e857e55a645d8025c281cfaf6f24bbd193138dadfa09853afef2316c02bdc56584667190e2d99839cc6ec7dd9c5fb8930c
7
+ data.tar.gz: 4b6161d6efd1eb45d9c3a24775ff03c1308c52e015b39c9485f1386f97300d8c3c3e1711a38d6d1f7d9efda26cf8d021470f5cf5b996224984d4e749c1779ace
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in weather_alert_mbj.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 'Marcus Jun'
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,42 @@
1
+ # WeatherAlertMbj
2
+
3
+ This gem uses webscraping to get National Weather Service weather alerts by state. See https://alerts.weather.gov/
4
+
5
+ ## Installation
6
+
7
+ (You can clone or download the code from https://github.com/marcusjun/weather-alert-mbj-cli-app)
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'weather_alert_mbj'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install weather_alert_mbj
22
+
23
+
24
+ ## Usage
25
+
26
+ Run the executable in bin/weather-alert-mbj with the following command
27
+
28
+ ```$ ./bin/weather-alert-mbj```
29
+
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ 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).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcusjun/weather_alert_mbj.
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+
5
+ #Both require statements below work
6
+ #require "weather_alert_mbj"
7
+ require_relative '../lib/weather_alert_mbj'
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+
18
+ puts " Welcome to the Weather Alert Sandbox ".colorize(:color => :blue, :background => :light_white)
19
+
20
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #Both require statements below work
4
+ #require './lib/weather_alert_mbj'
5
+ require_relative '../lib/weather_alert_mbj'
6
+
7
+ #require "bundler/setup"
8
+ #require "weather_alert_mbj"
9
+
10
+ WeatherAlertMbj::CLI.new.call
@@ -0,0 +1,14 @@
1
+ require 'open-uri'
2
+ require 'pry'
3
+ require 'nokogiri'
4
+ require 'colorize'
5
+
6
+ #require "weather_alert_mbj/version"
7
+ require_relative "./weather_alert_mbj/version"
8
+
9
+ #module WeatherAlertMbj
10
+ # Your code goes here...
11
+ #end
12
+
13
+ require_relative './weather_alert_mbj/alert'
14
+ require_relative './weather_alert_mbj/cli'
@@ -0,0 +1,199 @@
1
+ class WeatherAlertMbj::CLI
2
+
3
+ STATE_CODES={
4
+ "al" => "Alabama",
5
+ "ak" => "Alaska",
6
+ "az" => "Arizona",
7
+ "ar" => "Arkansas",
8
+ "ca" => "California",
9
+ "co" => "Colorado",
10
+ "ct" => "Connecticut",
11
+ "de" => "Delware",
12
+ "dc" => "District of Columbia",
13
+ "fl" => "Florida",
14
+ "ga" => "Georgia",
15
+ "hi" => "Hawaii",
16
+ "id" => "Idaho",
17
+ "il" => "Illinois",
18
+ "in" => "Indiana",
19
+ "ia" => "Iowa",
20
+ "ks" => "Kansas",
21
+ "ky" => "Kentucky",
22
+ "la" => "Louisiana",
23
+ "me" => "Maine",
24
+ "md" => "Maryland",
25
+ "ma" => "Massachusetts",
26
+ "mi" => "Michigan",
27
+ "mn" => "Minnesota",
28
+ "ms" => "Mississippi",
29
+ "mo" => "Missouri",
30
+ "mt" => "Montana",
31
+ "ne" => "Nebraska",
32
+ "nv" => "Nevada",
33
+ "nh" => "New Hampshire",
34
+ "nj" => "New Jersey",
35
+ "nm" => "New Mexico",
36
+ "ny" => "New York",
37
+ "nc" => "North Carolina",
38
+ "nd" => "North Dakota",
39
+ "oh" => "Ohio",
40
+ "ok" => "Oklahoma",
41
+ "or" => "Oregon",
42
+ "pa" => "Pennsylvania",
43
+ "ri" => "Rhode Island",
44
+ "sc" => "South Carolina",
45
+ "sd" => "South Dakota",
46
+ "tn" => "Tennessee",
47
+ "tx" => "Texas",
48
+ "us" => "United States",
49
+ "ut" => "Utah",
50
+ "vt" => "Vermont",
51
+ "va" => "Virginia",
52
+ "wa" => "Washington",
53
+ "wv" => "West Virginia",
54
+ "wi" => "Wisconsin",
55
+ "wy" => "Wyoming",
56
+ #US territories and other
57
+ "as" => "American Samoa",
58
+ "gu" => "Guam",
59
+ "mp" => "Northern Mariana Islands",
60
+ "pr" => "Puerto Rico",
61
+ "vi" => "U.S. Virgin Islands",
62
+ "um" => "U.S. Minor Outlying Islands"
63
+ }
64
+
65
+
66
+ def call
67
+ line_break
68
+ puts "\nWelcome to Weather Alert.".colorize(:color => :blue)
69
+
70
+ get_state_and_its_alerts
71
+ goodbye
72
+ end
73
+
74
+ def get_state_and_its_alerts
75
+
76
+ state_input = ""
77
+
78
+ while state_input.downcase != "exit"
79
+ puts "\nPlease enter the two-letter code for the US state or territory\nyou wish to get weather alerts for.".colorize(:color => :green)
80
+ puts " For example, CA = California and TX = Texas"
81
+ puts " Or type 'Exit' to quit Weather Alert."
82
+
83
+ state_input = gets.strip.downcase
84
+
85
+ #Conditional statement that ensures user input is a valid state code or valid state name
86
+ if STATE_CODES.keys.include?(state_input) || STATE_CODES.any? {|state_code,state_name| state_name.downcase == state_input}
87
+
88
+ #If user inputs full name of state (California) rather than its code (CA)
89
+ #then the following code assigns state_input to the state code.
90
+ STATE_CODES.each {|state_code,state_name| state_input = STATE_CODES.key(state_name) if state_input == state_name.downcase}
91
+
92
+ puts "\nLoading data for " + "#{STATE_CODES[state_input]}".colorize(:color => :blue) + "..."
93
+ puts "(It may take up to 1 minute to retrieve data.)"
94
+ line_break
95
+
96
+ @state_alerts = WeatherAlertMbj::Alert.create_alerts(state_input)
97
+
98
+ get_and_display_alert_details
99
+
100
+ elsif state_input.downcase != "exit"
101
+ line_break
102
+ puts "\n Please double check the code you entered. ".colorize(:color => :light_white, :background => :red)#(:color => :red)
103
+ line_break
104
+ end
105
+
106
+ end
107
+ end
108
+
109
+ def get_and_display_alert_details
110
+ display_alerts
111
+
112
+ menu_input = ""
113
+
114
+ while menu_input.downcase != "exit"
115
+
116
+ if @state_alerts[0].name == "There are no active watches, warnings or advisories"
117
+
118
+ #If a state has no weather alerts, then menu_input is set to "exit"
119
+ #because there are no alerts to get more details on.
120
+ menu_input = "exit"
121
+ line_break
122
+
123
+ else
124
+ line_break
125
+ puts "\nPlease enter the number (from 1 - #{@state_alerts.length}) of the alert for more details.".colorize(:color => :green)
126
+ puts " Or type 'List' to see a list of alerts."
127
+ puts " Or type 'Exit' to return to the previous menu."
128
+ line_break
129
+
130
+ menu_input = gets.strip.downcase
131
+
132
+ if menu_input.downcase == "list"
133
+ display_alerts
134
+
135
+ #elsif menu_input.to_i <= @state_alerts.length && menu_input.to_i > 0
136
+ elsif menu_input.to_i.between?(1,@state_alerts.length)
137
+
138
+ selected_alert = @state_alerts[menu_input.to_i-1]
139
+
140
+ #Displays the details of an alert including its
141
+ #name, state, urgency (if immediate), description, instructions and urls.
142
+
143
+ puts "\nAlert ##{menu_input}: #{selected_alert.name} (#{STATE_CODES[selected_alert.state]})".colorize(:color => :blue)
144
+
145
+ puts "Urgency: #{selected_alert.urgency}".colorize(:color => :red) if selected_alert.urgency.downcase == "immediate"
146
+
147
+ puts "\nDescription:".colorize(:color => :blue)
148
+ puts "#{selected_alert.description}"
149
+
150
+ #puts instructions if the alert's attribute, instructions is not an empty string
151
+ puts "\nInstructions:".colorize(:color => :blue) unless selected_alert.instructions == ""
152
+ puts "#{selected_alert.instructions}" unless selected_alert.instructions == ""
153
+
154
+ puts "\nFor more info, please see".colorize(:color => :blue)
155
+ puts "#{selected_alert.state_url}"
156
+ puts "#{selected_alert.alert_url}"
157
+
158
+ elsif menu_input != "exit"
159
+ puts "\n Please double check the number you entered. ".colorize(:color => :light_white, :background => :red)
160
+ end
161
+ end
162
+ end
163
+ end
164
+
165
+
166
+ def display_alerts
167
+
168
+ @state_alerts.each_with_index do |alert,index|
169
+
170
+ selected_state = STATE_CODES[alert.state]
171
+
172
+ if alert.name == "There are no active watches, warnings or advisories"
173
+ puts "\n Currently, #{alert.name.downcase} for #{selected_state}.".colorize(:color => :blue)
174
+
175
+ else
176
+ puts "\nAlert ##{index+1}: #{alert.name} (#{selected_state})".colorize(:color => :blue)
177
+
178
+ #Alerts with an "immediate" urgency have the text, "immediate" in red.
179
+ if alert.urgency.downcase == "immediate"
180
+ puts " Urgency: #{alert.urgency}".colorize(:color => :red)
181
+ else
182
+ puts " Urgency: #{alert.urgency}"
183
+ end
184
+
185
+ puts " Areas: #{alert.areas_affected}"
186
+ puts " Date: #{alert.date}"
187
+ end
188
+ end
189
+ end
190
+
191
+ def goodbye
192
+ puts "\nThanks for using Weather Alert. Goodbye.".colorize(:color => :blue)
193
+ puts " For more weather alerts, please visit https://alerts.weather.gov/\n".colorize(:color => :blue)
194
+ end
195
+
196
+ def line_break
197
+ puts "\n-------------------------------------------------------------------------------------".colorize(:color => :light_white)
198
+ end
199
+ end
@@ -0,0 +1,3 @@
1
+ module WeatherAlertMbj
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,44 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "weather_alert_mbj/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "weather_alert_mbj"
8
+ spec.version = WeatherAlertMbj::VERSION
9
+ spec.authors = ["Marcus Jun"]
10
+ spec.email = [""]
11
+
12
+ spec.summary = "This gem uses webscraping to get National Weather Service weather alerts by state. See https://alerts.weather.gov/"
13
+ #%q{TODO: Write a short summary, because RubyGems requires one.}
14
+ spec.description = "The user enters a US state or territory and the gem returns a list of weather alerts. Then user can choose a weather alert to see more details."
15
+ #%q{TODO: Write a longer description or delete this line.}
16
+ spec.homepage = "https://github.com/marcusjun/weather-alert-mbj-cli-app"
17
+ #"TODO: Put your gem's website or public repo URL here."
18
+ spec.license = "MIT"
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ #if spec.respond_to?(:metadata)
23
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
24
+ #else
25
+ #raise "RubyGems 2.0 or newer is required to protect against " \
26
+ #"public gem pushes."
27
+ #end
28
+
29
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
30
+ f.match(%r{^(test|spec|features)/})
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.16"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+
39
+ # My modifications below
40
+ #spec.add_development_dependency "pry"
41
+ spec.add_dependency "nokogiri", "~> 1.6"
42
+ spec.add_dependency "colorize", "~> 0.8.1"
43
+
44
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather_alert_mbj
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcus Jun
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.1
69
+ description: The user enters a US state or territory and the gem returns a list of
70
+ weather alerts. Then user can choose a weather alert to see more details.
71
+ email:
72
+ - ''
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - bin/weather-alert-mbj
85
+ - lib/weather_alert_mbj.rb
86
+ - lib/weather_alert_mbj/cli.rb
87
+ - lib/weather_alert_mbj/version.rb
88
+ - weather_alert_mbj.gemspec
89
+ homepage: https://github.com/marcusjun/weather-alert-mbj-cli-app
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.7.7
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: This gem uses webscraping to get National Weather Service weather alerts
113
+ by state. See https://alerts.weather.gov/
114
+ test_files: []