blinkenstein 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.
- data/.chef/knife.rb +13 -0
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/bin/blinkenstein +16 -0
- data/blinkenstein.gemspec +27 -0
- data/chef/cookbooks/.gitkeep +0 -0
- data/chef/data_bags/.gitkeep +0 -0
- data/chef/nodes/.gitkeep +0 -0
- data/chef/nodes/192.168.1.110.json +1 -0
- data/chef/roles/.gitkeep +0 -0
- data/chef/site-cookbooks/.gitkeep +0 -0
- data/chef/solo.rb +6 -0
- data/lib/blinkenstein/blink.rb +83 -0
- data/lib/blinkenstein/monitors/eve.rb +81 -0
- data/lib/blinkenstein/runner.rb +22 -0
- data/lib/blinkenstein/version.rb +3 -0
- data/lib/blinkenstein.rb +13 -0
- metadata +162 -0
data/.chef/knife.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
log_level :info
|
2
|
+
log_location STDOUT
|
3
|
+
node_name ENV["NODE_NAME"] || "solo"
|
4
|
+
client_key File.expand_path("../solo.pem", __FILE__)
|
5
|
+
cache_type "BasicFile"
|
6
|
+
cache_options(path: File.expand_path("../checksums", __FILE__))
|
7
|
+
cookbook_path [ File.expand_path("../../chef/cookbooks", __FILE__) ]
|
8
|
+
solo_path "chef"
|
9
|
+
# Allow users to add or override knife locally
|
10
|
+
if ::File.exist?(File.expand_path("../knife.local.rb", __FILE__))
|
11
|
+
Chef::Config.from_file(File.expand_path("../knife.local.rb", __FILE__))
|
12
|
+
end
|
13
|
+
puts File.expand_path("../../chef", __FILE__)
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Michael Schmidt
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Blinkenstein
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'blinkenstein'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install blinkenstein
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Provision chef-client to Raspberry Pi:
|
22
|
+
|
23
|
+
cd chef
|
24
|
+
../bin/knife solo prepare pi@192.168.1.110
|
25
|
+
|
26
|
+
Cook it:
|
27
|
+
|
28
|
+
bin/knife
|
29
|
+
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/blinkenstein
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'blinkenstein' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('blinkenstein', 'blinkenstein')
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'blinkenstein/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "blinkenstein"
|
8
|
+
gem.version = Blinkenstein::VERSION
|
9
|
+
gem.authors = ["Michael Schmidt"]
|
10
|
+
gem.email = ["michael.j.schmidt@gmail.com"]
|
11
|
+
gem.description = %q{Blink(1) Monitoring Thinggy}
|
12
|
+
gem.summary = %q{Currently monitors Eve Online's skill queue and messes with Blink(1)'}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency('rspec')
|
21
|
+
gem.add_development_dependency('knife-solo')
|
22
|
+
|
23
|
+
gem.add_dependency('celluloid')
|
24
|
+
gem.add_dependency('rb-blink1')
|
25
|
+
gem.add_dependency('httparty')
|
26
|
+
gem.add_dependency('nokogiri')
|
27
|
+
end
|
File without changes
|
File without changes
|
data/chef/nodes/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
{"run_list":[]}
|
data/chef/roles/.gitkeep
ADDED
File without changes
|
File without changes
|
data/chef/solo.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'blink1'
|
2
|
+
require 'celluloid'
|
3
|
+
|
4
|
+
class Blinkenstein::Blink
|
5
|
+
include Celluloid
|
6
|
+
|
7
|
+
attr_reader :timer
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
blink.open
|
11
|
+
end
|
12
|
+
|
13
|
+
def finalize
|
14
|
+
puts "Closing Blink1 Connection"
|
15
|
+
blink.off
|
16
|
+
blink.close
|
17
|
+
end
|
18
|
+
|
19
|
+
def breath(hex = "#0000ff", duration = 5, depth = 0.2)
|
20
|
+
play(animate_breath(hex, duration, depth))
|
21
|
+
end
|
22
|
+
|
23
|
+
def police
|
24
|
+
animation = animate_breath("#ff0000", 0.5, 1) + animate_breath("#0000ff", 0.5, 1)
|
25
|
+
play(animation)
|
26
|
+
end
|
27
|
+
|
28
|
+
def play(animation, step = 0)
|
29
|
+
timer.cancel if timer
|
30
|
+
|
31
|
+
step = 0 if step >= animation.length
|
32
|
+
r, g, b, t = animation[step]
|
33
|
+
|
34
|
+
@timer = after(t) do
|
35
|
+
play(animation, step + 1)
|
36
|
+
end
|
37
|
+
|
38
|
+
blink.fade_to_rgb(t*1000, r, g, b)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# Amount should be a decimal between 0 and 1. Lower means darker
|
43
|
+
def darken_color(hex_color, amount=0.4)
|
44
|
+
hex_color = hex_color.gsub('#','')
|
45
|
+
rgb = hex_color.scan(/../).map {|color| color.hex}
|
46
|
+
rgb[0] = (rgb[0].to_i * amount).round
|
47
|
+
rgb[1] = (rgb[1].to_i * amount).round
|
48
|
+
rgb[2] = (rgb[2].to_i * amount).round
|
49
|
+
rgb
|
50
|
+
end
|
51
|
+
|
52
|
+
# Amount should be a decimal between 0 and 1. Higher means lighter
|
53
|
+
def lighten_color(hex_color, amount=0.6)
|
54
|
+
hex_color = hex_color.gsub('#','')
|
55
|
+
rgb = hex_color.scan(/../).map {|color| color.hex}
|
56
|
+
rgb[0] = [(rgb[0].to_i + 255 * amount).round, 255].min
|
57
|
+
rgb[1] = [(rgb[1].to_i + 255 * amount).round, 255].min
|
58
|
+
rgb[2] = [(rgb[2].to_i + 255 * amount).round, 255].min
|
59
|
+
rgb
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def animate_breath(hex = "#0000ff", duration = 5, depth = 0.2)
|
64
|
+
breath_in_duration = 1.0
|
65
|
+
breath_out_duration = 1.3
|
66
|
+
|
67
|
+
breath_in_interval = 0.1 * duration * breath_in_duration / (breath_in_duration + breath_out_duration)
|
68
|
+
breath_out_interval = 0.1 * duration * breath_out_duration / (breath_in_duration + breath_out_duration)
|
69
|
+
|
70
|
+
ease_in = [1.0000, 0.9933, 0.9707, 0.9277, 0.8573, 0.7487, 0.5872, 0.3685, 0.1541, 0.0325, 0.0000].map{|v| [v, breath_in_interval] }
|
71
|
+
ease_out = [1.0000, 0.9859, 0.9426, 0.8694, 0.7666, 0.6362, 0.4841, 0.3212, 0.1664, 0.0476, 0.0000].reverse.map{|v| [v, breath_out_interval] }
|
72
|
+
|
73
|
+
(ease_in + ease_out).map do |v, t|
|
74
|
+
darken_color(hex, 1 - (v * depth)) << t
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def blink
|
81
|
+
@@blink ||= Blink1.new
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'celluloid'
|
2
|
+
require 'httparty'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module Blinkenstein
|
6
|
+
class EveMonitor
|
7
|
+
include Celluloid
|
8
|
+
include HTTParty
|
9
|
+
|
10
|
+
base_uri 'https://api.eveonline.com'
|
11
|
+
|
12
|
+
def initialize(blink)
|
13
|
+
@blink = blink
|
14
|
+
@options = YAML.load(File.read(File.expand_path('~/.blinkenstein')))
|
15
|
+
end
|
16
|
+
|
17
|
+
def refresh
|
18
|
+
response = self.class.get('/char/SkillQueue.xml.aspx', query: @options)
|
19
|
+
cached_for_seconds, hours_until_empty = parse(response)
|
20
|
+
|
21
|
+
puts "Cached for #{cached_for_seconds} seconds"
|
22
|
+
puts "Skill queue empty in #{hours_until_empty} hours"
|
23
|
+
|
24
|
+
update_blink(hours_until_empty)
|
25
|
+
ensure
|
26
|
+
after(cached_for_seconds || 60) do
|
27
|
+
refresh
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse(response)
|
32
|
+
skills_for_hours = -1
|
33
|
+
cached_for_seconds = 60
|
34
|
+
|
35
|
+
currentTime = DateTime.strptime(response["eveapi"]['currentTime'], '%Y-%m-%d %H:%M:%S')
|
36
|
+
cachedUntil = DateTime.strptime(response["eveapi"]['cachedUntil'], '%Y-%m-%d %H:%M:%S')
|
37
|
+
skills = ([] << response["eveapi"]["result"]["rowset"]["row"]).flatten.last
|
38
|
+
|
39
|
+
cached_for_seconds = ((cachedUntil - currentTime) * 24 * 60 * 60).to_i
|
40
|
+
|
41
|
+
puts skills.inspect
|
42
|
+
if skills && skills["endTime"] && skills['endTime'] != ''
|
43
|
+
endTime = DateTime.strptime(skills["endTime"], '%Y-%m-%d %H:%M:%S')
|
44
|
+
skills_for_hours = ((endTime - currentTime) * 24).to_i
|
45
|
+
end
|
46
|
+
[cached_for_seconds, skills_for_hours]
|
47
|
+
ensure
|
48
|
+
[cached_for_seconds, skills_for_hours]
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def update_blink(hours_until_empty)
|
53
|
+
case hours_until_empty
|
54
|
+
when -1..8 then panic
|
55
|
+
when 9..24 then nervous
|
56
|
+
when Integer then cool
|
57
|
+
else error
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def cool
|
62
|
+
puts "Everything is cool"
|
63
|
+
@blink.breath("#00ff00", 4, 0.2)
|
64
|
+
end
|
65
|
+
|
66
|
+
def nervous
|
67
|
+
puts "There's room in the queue"
|
68
|
+
@blink.breath("#ff0000", 3, 0.3)
|
69
|
+
end
|
70
|
+
|
71
|
+
def panic
|
72
|
+
puts "Queue runs out soon."
|
73
|
+
@blink.police
|
74
|
+
end
|
75
|
+
|
76
|
+
def error
|
77
|
+
puts "Ehm. Something is wrong"
|
78
|
+
@blink.breath("#ff0000", 0.25, 0.75)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'celluloid'
|
2
|
+
|
3
|
+
module Blinkenstein
|
4
|
+
class Runner
|
5
|
+
include Celluloid
|
6
|
+
|
7
|
+
attr_reader :blink
|
8
|
+
attr_reader :monitors
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@monitors = []
|
12
|
+
@blink = Blink.new
|
13
|
+
|
14
|
+
register(EveMonitor.new(blink))
|
15
|
+
end
|
16
|
+
|
17
|
+
def register(monitor)
|
18
|
+
@monitors << monitor
|
19
|
+
monitor.refresh
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/blinkenstein.rb
ADDED
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blinkenstein
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Schmidt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
type: :development
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: knife-solo
|
32
|
+
type: :development
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: celluloid
|
48
|
+
type: :runtime
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rb-blink1
|
64
|
+
type: :runtime
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: httparty
|
80
|
+
type: :runtime
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: nokogiri
|
96
|
+
type: :runtime
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Blink(1) Monitoring Thinggy
|
111
|
+
email:
|
112
|
+
- michael.j.schmidt@gmail.com
|
113
|
+
executables:
|
114
|
+
- blinkenstein
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .chef/knife.rb
|
119
|
+
- .gitignore
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/blinkenstein
|
125
|
+
- blinkenstein.gemspec
|
126
|
+
- chef/cookbooks/.gitkeep
|
127
|
+
- chef/data_bags/.gitkeep
|
128
|
+
- chef/nodes/.gitkeep
|
129
|
+
- chef/nodes/192.168.1.110.json
|
130
|
+
- chef/roles/.gitkeep
|
131
|
+
- chef/site-cookbooks/.gitkeep
|
132
|
+
- chef/solo.rb
|
133
|
+
- lib/blinkenstein.rb
|
134
|
+
- lib/blinkenstein/blink.rb
|
135
|
+
- lib/blinkenstein/monitors/eve.rb
|
136
|
+
- lib/blinkenstein/runner.rb
|
137
|
+
- lib/blinkenstein/version.rb
|
138
|
+
homepage: ''
|
139
|
+
licenses: []
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ! '>='
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 1.8.23
|
159
|
+
signing_key:
|
160
|
+
specification_version: 3
|
161
|
+
summary: Currently monitors Eve Online's skill queue and messes with Blink(1)'
|
162
|
+
test_files: []
|