lita-onewheel-halfstaff 0.0.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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +9 -0
- data/Gemfile +3 -0
- data/README.md +20 -0
- data/Rakefile +6 -0
- data/lib/lita/handlers/onewheel_halfstaff.rb +89 -0
- data/lib/lita-onewheel-halfstaff.rb +12 -0
- data/lita-onewheel-halfstaff.gemspec +30 -0
- data/spec/fixtures/halfstaff.html +735 -0
- data/spec/lita/handlers/onewheel_halfstaff_spec.rb +32 -0
- data/spec/spec_helper.rb +14 -0
- metadata +199 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 582efd3589c1f029b3b6bfa7cd74cc695732b0f4
|
4
|
+
data.tar.gz: 65c32fd452d656d93a8cdace64aa96db589cdbd8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 654f8dec79366a93e00c79a7a3ac10320029383f20ea92d745212bd0580eb5bbde7d5a912832bf3f5108fb99cce9dcb794b06e08d532ab2470815b84be0ba6d3
|
7
|
+
data.tar.gz: 2babac5de926d26f2d7afb5509d4cda1d1ed3c9f88d80ce1e7e10886b21cffcb64219bbb0cb5499603b7901363f912dc501b876067ca8003c819a0e91f461842
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# lita-onewheel-halfstaff
|
2
|
+
|
3
|
+
[](https://travis-ci.org/onewheelskyward/lita-onewheel-halfstaff)
|
4
|
+
[](https://coveralls.io/github/onewheelskyward/lita-onewheel-halfstaff?branch=master)
|
5
|
+
|
6
|
+
Find out why your American flag is at half-staff, based on http://www.flagsexpress.com/HalfStaff_s/1852.html.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add lita-onewheel-halfstaff to your Lita instance's Gemfile:
|
11
|
+
|
12
|
+
``` ruby
|
13
|
+
gem 'lita-onewheel-halfstaff'
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
!halfstaff - get current half staff notices.
|
19
|
+
!halfstaff history - Get a link to the history of flying flags half-mast.
|
20
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'restclient'
|
3
|
+
|
4
|
+
module Lita
|
5
|
+
module Handlers
|
6
|
+
class OnewheelHalfstaff < Handler
|
7
|
+
route /^halfstaff$/,
|
8
|
+
:get_flag_status,
|
9
|
+
command: true
|
10
|
+
|
11
|
+
route /^halfstaff history$/,
|
12
|
+
:get_history,
|
13
|
+
command: true
|
14
|
+
|
15
|
+
def get_flag_status(response)
|
16
|
+
flag_data = get_flag_data
|
17
|
+
if flag_data.empty?
|
18
|
+
Lita.logger.info 'No flag match for today.'
|
19
|
+
response.reply ["Everything's cool, yo.", 'No half staff known.'].sample
|
20
|
+
else
|
21
|
+
Lita.logger.info 'Got a match on the flag.'
|
22
|
+
flag_data.each do |reply|
|
23
|
+
response.reply reply
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_flag_data
|
29
|
+
flag_html = RestClient.get 'http://www.flagsexpress.com/HalfStaff_s/1852.htm'
|
30
|
+
results = []
|
31
|
+
noko_flag = Nokogiri::HTML flag_html
|
32
|
+
noko_flag.css('a').each do |a_tag|
|
33
|
+
if a_tag['href'].match /http\:\/\/www\.flagsexpress\.com\/Articles\.asp\?ID\=/i
|
34
|
+
if is_at_half_staff(a_tag.text)
|
35
|
+
pieces = a_tag.text.split(/ - /)
|
36
|
+
Lita.logger.info 'Returning flag data'
|
37
|
+
results.push "#{pieces[1]} - #{pieces[2]} - #{a_tag['href']}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
results
|
42
|
+
end
|
43
|
+
|
44
|
+
def is_at_half_staff(text)
|
45
|
+
Lita.logger.info "Checking for flag date match on #{text}"
|
46
|
+
half_staff = false
|
47
|
+
pieces = text.split(/ - /)
|
48
|
+
current_year = Date::today.year
|
49
|
+
if pieces[0].match(/#{current_year}/)
|
50
|
+
if date_matches = pieces[0].match(/(\w+\s+\d+,\s+\d+)/) # February 26, 2016
|
51
|
+
# Lita.logger.info 'Standard'
|
52
|
+
# Lita.logger.info date_matches[1]
|
53
|
+
date = Date::parse(date_matches[1])
|
54
|
+
half_staff = date == Date::today
|
55
|
+
elsif date_matches = pieces[0].match(/(\w+)\s+(\d+)-(\d+)/) # March 5-11, 2016
|
56
|
+
# Lita.logger.info 'Date range'
|
57
|
+
month = date_matches[1]
|
58
|
+
day_start = date_matches[2]
|
59
|
+
day_end = date_matches[3]
|
60
|
+
half_staff = does_today_match_date_range(month, day_start, month, day_end, current_year)
|
61
|
+
elsif date_matches = pieces[0].match(/(\w+)\s+(\d+) until sunset \w+, (\w+)\s+(\d+)/i) # May 3 until sunset Sunday, December 12
|
62
|
+
# Lita.logger.info 'until sunset'
|
63
|
+
start_month = date_matches[1]
|
64
|
+
start_day = date_matches[2]
|
65
|
+
end_month = date_matches[3]
|
66
|
+
end_day = date_matches[4]
|
67
|
+
half_staff = does_today_match_date_range(start_month, start_day, end_month, end_day, current_year)
|
68
|
+
else
|
69
|
+
Lita.logger.info "Couldn't match #{pieces[0]}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
half_staff
|
74
|
+
end
|
75
|
+
|
76
|
+
def does_today_match_date_range(month_start, day_start, month_end, day_end, current_year)
|
77
|
+
start_time = DateTime::parse("#{month_start} #{day_start} #{current_year} 00:00")
|
78
|
+
end_time = DateTime::parse("#{month_end} #{day_end} #{current_year} 23:59")
|
79
|
+
return (start_time..end_time).include? Time.now
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_history(response)
|
83
|
+
response.reply 'https://en.wikipedia.org/wiki/Half-mast'
|
84
|
+
end
|
85
|
+
|
86
|
+
Lita.register_handler(self)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'lita'
|
2
|
+
|
3
|
+
# Lita.load_locales Dir[File.expand_path(
|
4
|
+
# File.join('..', '..', 'locales', '*.yml'), __FILE__
|
5
|
+
# )]
|
6
|
+
|
7
|
+
require 'lita/handlers/onewheel_halfstaff'
|
8
|
+
|
9
|
+
Lita::Handlers::OnewheelHalfstaff.template_root File.expand_path(
|
10
|
+
File.join('..', '..', 'templates'),
|
11
|
+
__FILE__
|
12
|
+
)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'lita-onewheel-halfstaff'
|
3
|
+
spec.version = '0.0.0'
|
4
|
+
spec.authors = ['Andrew Kreps']
|
5
|
+
spec.email = ['andrew.kreps@gmail.com']
|
6
|
+
spec.description = %q{View the current US flag half-staff status.}
|
7
|
+
spec.summary = %q{See above.}
|
8
|
+
spec.homepage = 'https://github.com/onewheelskyward/lita-onewheel-halfstaff'
|
9
|
+
spec.license = 'MIT'
|
10
|
+
spec.metadata = { 'lita_plugin_type' => 'handler'}
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ['lib']
|
16
|
+
|
17
|
+
spec.add_runtime_dependency 'lita', '~> 4.7'
|
18
|
+
spec.add_runtime_dependency 'rest-client', '~> 1.8'
|
19
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
# spec.add_development_dependency 'pry-byebug', '~> 3.1'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
24
|
+
spec.add_development_dependency 'rack-test', '~> 0.6'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'simplecov', '~> 0.10'
|
27
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'timecop', '~> 0.8'
|
30
|
+
end
|