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 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
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ - 2.3.0
5
+ script: bundle exec rake
6
+ before_install:
7
+ - gem update --system
8
+ services:
9
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # lita-onewheel-halfstaff
2
+
3
+ [![Build Status](https://travis-ci.org/onewheelskyward/lita-onewheel-halfstaff.png?branch=master)](https://travis-ci.org/onewheelskyward/lita-onewheel-halfstaff)
4
+ [![Coverage Status](https://coveralls.io/repos/github/onewheelskyward/lita-onewheel-halfstaff/badge.svg?branch=master)](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,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -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