thunderbuddies 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/thunderbuddies +5 -0
- data/lib/thunderbuddies.rb +8 -0
- data/lib/thunderbuddies/cli.rb +17 -0
- data/lib/thunderbuddies/image.rb +103 -0
- data/lib/thunderbuddies/system.rb +36 -0
- data/lib/thunderbuddies/version.rb +3 -0
- data/thunderbuddies.gemspec +33 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16771253a3ae636c1366cb917f0a82240cad4747
|
4
|
+
data.tar.gz: 2fb4bb936495c068c13e3db2476c5f6c4b8fdc8c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8cf6673e3c08f6321b52985befd579cbd37fb7e1b02267f5cee8e570d67e46607689d13a73338e7f0fa87c5287ccca3af7df317aef1e1592cf118b5f18a70ec
|
7
|
+
data.tar.gz: 070911279ad6013aa91a96a2c56ccd15a00ee09770623b66397d14df1c0f3d5ed1bfdcd2602aa7b9f6750d7565600216c6f357a68d5a5d1cb3559007e2551e0f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Thunderbuddies
|
2
|
+
|
3
|
+
[![thunderbuddies](http://img.youtube.com/vi/G9PnNW56bp0/0.jpg)](http://www.youtube.com/watch?v=G9PnNW56bp0)
|
4
|
+
|
5
|
+
Thunderbuddies are powerful tools to protect your server from blackout by thunders. Thunderbuddies tell your computer that a thunderstorm is coming and shut it down before it crashes. Please read the usage below carefully since currently features are limited.
|
6
|
+
|
7
|
+
## Requisites
|
8
|
+
|
9
|
+
- [ImageMagick](http://www.imagemagick.org/script/binary-releases.php)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'thunderbuddies'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install thunderbuddies
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Use an executable `thunderbuddies` to check the level of the thunder alert or to shut your computer down immediately if you are scared of it.
|
30
|
+
|
31
|
+
You can specify two arguments for `thunderbuddies level`, the first is for the name of your location and the last for the path to the directory to save the image of the thunder forecast.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
$ thunderbuddies level Tokyo $HOME/tmp
|
35
|
+
```
|
36
|
+
|
37
|
+
**WARNING**: Currently this is the experimental, so you can specify your location but it is ignored. If a thunder is coming to Mishima, where the [largest supercomputer system for the genomic science in Japan](http://sc.ddbj.nig.ac.jp/) is located, your computer will be shutting down regardless the weather on your location. I appreciate your sympathy.
|
38
|
+
|
39
|
+
Default parameter for the image directory is `/tmp`.
|
40
|
+
|
41
|
+
You can also specify three arguments for `thunderbuddies halt`; threshold of the alert level, your location, and the path to the directory to save the image. You need to run this command with root permission to access the shutdown command.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
$ sudo thunderbuddies halt 3 Asgard $HOME/tmp
|
45
|
+
```
|
46
|
+
|
47
|
+
The level of thunder alert is an integer from 0 to 4, default parameter is 4. Default parameter of the image directory is also `/tmp`.
|
48
|
+
|
49
|
+
**WARNING AGAIN**: You do not have to worry about specifying your location. When our supercomputer system in Mishima goes down, your computer will follow no matter how good the weather is on your place.
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/inutano/thunderbuddies.
|
54
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "thunderbuddies"
|
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
|
data/bin/setup
ADDED
data/exe/thunderbuddies
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module Thunderbuddies
|
6
|
+
class CLI < Thor
|
7
|
+
desc "level [LOCATION] [IMAGEDIR]", "Get the level of thunder 0-4 at LOCATION"
|
8
|
+
def level(location="Mishima", dir="/tmp")
|
9
|
+
puts Thunderbuddies::Image.new(location, dir).get_thunder_level
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "halt [LEVEL] [LOCATION] [IMAGEDIR]", "Shutting down the computer if the thunder level is equal to LEVEL or higher"
|
13
|
+
def halt(level=4, location="Mishima", dir="tmp")
|
14
|
+
Thunderbuddies::System.halt(level, location, dir)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module Thunderbuddies
|
7
|
+
class Image
|
8
|
+
def initialize(location, image_base_dir)
|
9
|
+
@location = location
|
10
|
+
@date = Time.now
|
11
|
+
@datetime = @date.strftime("%Y%m%d%H%M").to_i / 10 * 10
|
12
|
+
@image_dir = get_image_dir(image_base_dir)
|
13
|
+
@image = get_image_fname
|
14
|
+
end
|
15
|
+
attr_reader :image
|
16
|
+
|
17
|
+
def get_image_fname
|
18
|
+
fname = "thunderbuddies-#{@datetime}.png"
|
19
|
+
File.join(@image_dir, fname)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_image_dir(image_base_dir)
|
23
|
+
year = @date.strftime("%Y")
|
24
|
+
month = @date.strftime("%m")
|
25
|
+
day = @date.strftime("%d")
|
26
|
+
File.join(image_base_dir, year, month, day)
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_thunder_level
|
30
|
+
get_image(thunder_url)
|
31
|
+
check_image
|
32
|
+
end
|
33
|
+
|
34
|
+
def thunder_url
|
35
|
+
"#{base_url}/#{get_location_code}/#{@datetime}-01.png"
|
36
|
+
end
|
37
|
+
|
38
|
+
def base_url
|
39
|
+
"http://www.jma.go.jp/jp/radnowc/imgs/thunder"
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_location_code
|
43
|
+
"210" # Mishima
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_image(url)
|
47
|
+
create_dir(@image_dir)
|
48
|
+
save_image(url)
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_dir(dirpath)
|
52
|
+
FileUtils.mkdir_p(dirpath) if !File.exist?(dirpath)
|
53
|
+
end
|
54
|
+
|
55
|
+
def save_image(url)
|
56
|
+
open(@image, 'wb') do |output|
|
57
|
+
open(url) do |data|
|
58
|
+
output.write(data.read)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
rescue OpenURI::HTTPError
|
62
|
+
puts "OpenURI got an error, possibly thunder image is not yet ready. Try later"
|
63
|
+
exit(1)
|
64
|
+
end
|
65
|
+
|
66
|
+
def check_image
|
67
|
+
cropped_image = convert_image
|
68
|
+
image_info = identify_image(cropped_image)
|
69
|
+
evaluate(image_info)
|
70
|
+
end
|
71
|
+
|
72
|
+
def convert_image
|
73
|
+
cropped_image = "#{@image}.cropped.png"
|
74
|
+
`convert -crop 50x50+300+100 #{@image} #{cropped_image}`
|
75
|
+
cropped_image
|
76
|
+
rescue Errno::ENOENT
|
77
|
+
puts "Imagemagick is required http://www.imagemagick.org/script/binary-releases.php"
|
78
|
+
exit(1)
|
79
|
+
end
|
80
|
+
|
81
|
+
def identify_image(cropped_image)
|
82
|
+
`identify -verbose #{cropped_image} | grep Histogram -A 10 | grep -E '#FAF500|#FF2800|#FFAA00|#C800FF'`
|
83
|
+
rescue Errno::ENOENT
|
84
|
+
puts "Imagemagick is required http://www.imagemagick.org/script/binary-releases.php"
|
85
|
+
exit(1)
|
86
|
+
end
|
87
|
+
|
88
|
+
def evaluate(image_info)
|
89
|
+
case image_info
|
90
|
+
when /#C800FF/
|
91
|
+
4
|
92
|
+
when /#FFAA00/
|
93
|
+
3
|
94
|
+
when /#FF2800/
|
95
|
+
2
|
96
|
+
when /#FAF500/
|
97
|
+
1
|
98
|
+
else
|
99
|
+
0
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Thunderbuddies
|
4
|
+
class System
|
5
|
+
class << self
|
6
|
+
def halt(level, location, dir)
|
7
|
+
if emergency?(level, location, dir)
|
8
|
+
shutdown
|
9
|
+
else
|
10
|
+
puts "Hey buddy, I'm OK.."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def emergency?(level, location, dir)
|
15
|
+
image = Thunderbuddies::Image.new(location, dir)
|
16
|
+
current_level = image.get_thunder_level
|
17
|
+
current_level >= level.to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
def shutdown
|
21
|
+
puts "shutting down in 5 seconds:"
|
22
|
+
sleep 1
|
23
|
+
puts "4"
|
24
|
+
sleep 1
|
25
|
+
puts "3"
|
26
|
+
sleep 1
|
27
|
+
puts "2"
|
28
|
+
sleep 1
|
29
|
+
puts "1"
|
30
|
+
sleep 1
|
31
|
+
puts "bye."
|
32
|
+
`sudo shutdown -h now`
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'thunderbuddies/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "thunderbuddies"
|
8
|
+
spec.version = Thunderbuddies::VERSION
|
9
|
+
spec.authors = ["Tazro Inutano Ohta"]
|
10
|
+
spec.email = ["inutano@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Protect your server from blackout by thunder}
|
13
|
+
spec.description = %q{Shut down server before going down by blackout, currently it works in Japan only.}
|
14
|
+
spec.homepage = "https://github.com/inutano/thunderbuddies"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec"
|
32
|
+
spec.add_dependency "thor"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thunderbuddies
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tazro Inutano Ohta
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-02 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Shut down server before going down by blackout, currently it works in
|
70
|
+
Japan only.
|
71
|
+
email:
|
72
|
+
- inutano@gmail.com
|
73
|
+
executables:
|
74
|
+
- thunderbuddies
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- exe/thunderbuddies
|
87
|
+
- lib/thunderbuddies.rb
|
88
|
+
- lib/thunderbuddies/cli.rb
|
89
|
+
- lib/thunderbuddies/image.rb
|
90
|
+
- lib/thunderbuddies/system.rb
|
91
|
+
- lib/thunderbuddies/version.rb
|
92
|
+
- thunderbuddies.gemspec
|
93
|
+
homepage: https://github.com/inutano/thunderbuddies
|
94
|
+
licenses: []
|
95
|
+
metadata:
|
96
|
+
allowed_push_host: https://rubygems.org
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.4.5
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Protect your server from blackout by thunder
|
117
|
+
test_files: []
|