nws-alert 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/alert.rb +63 -0
  3. data/lib/nws-alert.rb +74 -0
  4. metadata +115 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2c062be07ff71b01833f2d6d331a34b97dc3239
4
+ data.tar.gz: 2856b2c0135e33edaf114a36a0406a1924fe2b19
5
+ SHA512:
6
+ metadata.gz: d7ea667368e1395c5eac9c4e914e28669decb240336b3cc305b8e8984ccb31f0bc83d4627ffb77163e14478175c7090ceb19d93ab888b7fcb852e15cd3b3b3f7
7
+ data.tar.gz: eace1eddca01b9970054d55c9d6252fc2a31f6410cd78d1e2ecee7ad980f7712163e2f3c95e030de8b9077c44f4040868d26da110cf5ab32fa56d6f21c7e7b78
data/lib/alert.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'date'
2
+
3
+ module Nws
4
+ class Alert
5
+ attr_reader :status,
6
+ :note,
7
+ :event,
8
+ :urgency,
9
+ :severity,
10
+ :certainty,
11
+ :effective,
12
+ :expires,
13
+ :sender_name,
14
+ :headline,
15
+ :description,
16
+ :affected_area
17
+
18
+ def initialize(entry)
19
+ @entry = entry
20
+
21
+ find_status_and_notes_on_event
22
+ find_severity_and_likelihood_of_alert
23
+ find_sender_and_area_information
24
+ get_text_of_alert
25
+ end
26
+
27
+ private
28
+
29
+ def effective
30
+ parse_time(@entry['info']['effective'])
31
+ end
32
+
33
+ def expires
34
+ parse_time(@entry['info']['expires'])
35
+ end
36
+
37
+ def find_status_and_notes_on_event
38
+ @status = @entry['status']
39
+ @note = @entry['note']
40
+ @event = @entry['info']['event']
41
+ end
42
+
43
+ def find_severity_and_likelihood_of_alert
44
+ @urgency = @entry['info']['urgency']
45
+ @severity = @entry['info']['severity']
46
+ @certainty = @entry['info']['certainty']
47
+ end
48
+
49
+ def find_sender_and_area_information
50
+ @sender_name = @entry['info']['senderName']
51
+ @affected_area = @entry['info']['area']['areaDesc']
52
+ end
53
+
54
+ def get_text_of_alert
55
+ @headline = @entry['info']['headline']
56
+ @description = @entry['info']['description']
57
+ end
58
+
59
+ def parse_time(raw_datetime)
60
+ DateTime.parse(raw_datetime)
61
+ end
62
+ end
63
+ end
data/lib/nws-alert.rb ADDED
@@ -0,0 +1,74 @@
1
+ require 'httparty'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'alert'
5
+
6
+ module Nws
7
+ class Connect
8
+ attr_reader :alerts
9
+
10
+ def initialize(location)
11
+ @alerts = []
12
+ fetch(location)
13
+ end
14
+
15
+ private
16
+
17
+ def fetch(location)
18
+ unless /\d{5}/.match(location).nil?
19
+ xml = parse_weather_alerts_by_zone(location)
20
+ else
21
+ xml = HTTParty.get("http://alerts.weather.gov/cap/#{location}.php?x=0", format: :xml)
22
+ end
23
+ parse_entries(xml)
24
+ end
25
+
26
+ def parse_weather_alerts_by_zone(location)
27
+ lat_long = get_lat_long(location)
28
+ lat = lat_long.gsub(/,.{7,}/, '')
29
+ long = lat_long.gsub(/.{7,},/, '')
30
+
31
+ zone = scrape_for_zone(lat, long)
32
+
33
+ HTTParty.get("http://alerts.weather.gov/cap/wwaatmget.php?x=#{zone}&y=1", format: :xml)
34
+ end
35
+
36
+ def scrape_for_zone(lat, long)
37
+ doc = Nokogiri::HTML(open("http://forecast.weather.gov/MapClick.php?lat=#{lat}&lon=#{long}#.UwAsUmRdXue"))
38
+ div_containing_zone = doc.css('.current-conditions-extra')
39
+ anchor_containing_zone = div_containing_zone.css('a')
40
+ anchor_containing_zone.first.first[1].scan(/[A-Z]{3}\d{3}/).first
41
+ end
42
+
43
+ def get_lat_long(location)
44
+ date = Time.now.to_s.gsub(/\s.{1,}/, '')
45
+ HTTParty.get("http://graphical.weather.gov/xml/SOAP_server/ndfdXMLclient.php?whichClient=LatLonListZipCode&lat=&lon=&listLatLon=&lat1=&lon1=&lat2=&lon2=&resolutionSub=&listLat1=&listLon1=&listLat2=&listLon2=&resolutionList=&endPoint1Lat=&endPoint1Lon=&endPoint2Lat=&endPoint2Lon=&listEndPoint1Lat=&listEndPoint1Lon=&listEndPoint2Lat=&listEndPoint2Lon=&zipCodeList=&listZipCodeList=#{location}&centerPointLat=&centerPointLon=&distanceLat=&distanceLon=&resolutionSquare=&listCenterPointLat=&listCenterPointLon=&listDistanceLat=&listDistanceLon=&listResolutionSquare=&citiesLevel=&listCitiesLevel=&sector=&gmlListLatLon=&featureType=&requestedTime=&startTime=&endTime=&compType=&propertyName=&product=time-series&begin=#{date}T00%3A00%3A00&end=#{date}T00%3A00%3A00&Unit=e&wwa=wwa&Submit=Submit", format: :xml)['dwml']['latLonList']
46
+ end
47
+
48
+ def parse_entries(xml)
49
+ entries = xml['feed']['entry']
50
+ unless entries['title'] == "There are no active watches, warnings or advisories"
51
+ get_alerts_at_location(entries)
52
+ else
53
+ no_alerts_available
54
+ end
55
+ end
56
+
57
+ def get_alerts_at_location(entries)
58
+ # entries.each do |entry|
59
+ # item = HTTParty.get(entry[1], format: :xml)['alert']
60
+ item = HTTParty.get(entries['id'], format: :xml)['alert']
61
+ alert = Alert.new(item) unless item.nil?
62
+ @alerts << alert
63
+ # end
64
+ end
65
+
66
+ def no_alerts_available
67
+ begin
68
+ raise StandardError, "There are no active watches or warnings in the area specified"
69
+ rescue Exception => e
70
+ puts e.message
71
+ end
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nws-alert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Nicole Paz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.17'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.17'
83
+ description: Obtain weather alerts from NOAA. Look up information by zip code or state.
84
+ email: me@nicolejpaz.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - lib/alert.rb
90
+ - lib/nws-alert.rb
91
+ homepage: https://github.com/nicolejpaz/nws-alert
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Obtain NOAA weather alerts.
115
+ test_files: []