co2-notify 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 128eeb963f5de2e2a710b38ec44be5c135781fb7
4
- data.tar.gz: 9c13992a128c5a30bf3dc3d019a4436af45d6d8f
3
+ metadata.gz: 656c1119c1229e7d4cafdae776a7491e0adb61af
4
+ data.tar.gz: a6ef10621f4b2303cf76a84d0ac21093b6cc70fb
5
5
  SHA512:
6
- metadata.gz: ed54f54526f35123f407b250393918ce2f611032ed5cf60376af4ca64b4524eeec08e259811452b4e292eab0bf2b01ae5551b2b7e550fc7e8e60a316ec5b7f89
7
- data.tar.gz: 1d37e84a0385de48d2e266cc46ec37ea1925d60969782f75a0cbf95fb73a9a9adf69988363a7ee8cbfb971a576828b0c768ea26ae6274be50df85418d8aa1f30
6
+ metadata.gz: 642c10670207bb1f234ca3b1d8c1e2f0186d1cff24348a39770cd8c89bc1eb7205d902590f72974ef1382497f17ff3a62289faa7eddc4fb73c0ee331cc36cf88
7
+ data.tar.gz: de9473448fbc5a1071d198a4b4d86738f80c5197edeaa09790f87ea890d2f5bcb7e2cb9f287ec03db36b4594481139b694752956f291298bcb51ca377f86b5b2
data/README.md CHANGED
@@ -11,4 +11,9 @@
11
11
  ## Usage
12
12
 
13
13
  $ co2-notify init
14
+ $ co2-notify go
15
+
16
+ ## Autoload
17
+
18
+ $ co2-notify autoload $(which co2-notify)
14
19
  $ co2-notify start
data/co2-notify.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "hipchat"
23
23
  spec.add_dependency "activesupport"
24
24
  spec.add_dependency "co2mon"
25
+ spec.add_dependency "plist"
25
26
  end
@@ -6,6 +6,8 @@ class Co2Notify::Config < OpenStruct
6
6
  DEFAULT_COOLDOWN = 15.freeze
7
7
  DEFAULT_HIGH_LEVEL = 800.freeze
8
8
  DEFAULT_VERY_HIGH_LEVEL = 1200.freeze
9
+ DEFAULT_START_TIME = "12:00".freeze
10
+ DEFAULT_STOP_TIME = "19:00".freeze
9
11
 
10
12
  def self.get
11
13
  new YAML.load_file(config_file)
@@ -29,6 +31,10 @@ class Co2Notify::Config < OpenStruct
29
31
  h["high_level"] = STDIN.gets.chomp.presence || DEFAULT_HIGH_LEVEL
30
32
  print "Very High CO2 level (default: #{DEFAULT_VERY_HIGH_LEVEL}): "
31
33
  h["very_high_level"] = STDIN.gets.chomp.presence || DEFAULT_VERY_HIGH_LEVEL
34
+ print "Start time (default: #{DEFAULT_START_TIME}): "
35
+ h["start_time"] = STDIN.gets.chomp.presence || DEFAULT_START_TIME
36
+ print "Stop time (default: #{DEFAULT_STOP_TIME}): "
37
+ h["stop_time"] = STDIN.gets.chomp.presence || DEFAULT_STOP_TIME
32
38
  print "Mention (optional): "
33
39
  h["mention"] = STDIN.gets.chomp
34
40
  end
@@ -14,7 +14,12 @@ class Co2Notify::Notifier
14
14
 
15
15
  def start
16
16
  loop do
17
- notify
17
+ time = Time.now
18
+
19
+ if time > start_time && time < stop_time
20
+ notify
21
+ end
22
+
18
23
  sleep timeout * 60
19
24
  end
20
25
  rescue Interrupt
@@ -34,4 +39,12 @@ class Co2Notify::Notifier
34
39
  @status = new_status
35
40
  end
36
41
  end
42
+
43
+ def start_time
44
+ Time.parse(config.start_time)
45
+ end
46
+
47
+ def stop_time
48
+ Time.parse(config.stop_time)
49
+ end
37
50
  end
@@ -1,3 +1,3 @@
1
1
  class Co2Notify
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/co2-notify.rb CHANGED
@@ -1,26 +1,54 @@
1
1
  require "thor"
2
2
  require "co2mon"
3
3
  require "hipchat"
4
+ require "plist"
4
5
  require "active_support/core_ext/object/blank"
5
6
  require "active_support/core_ext/module/delegation"
6
7
 
7
8
  class Co2Notify < Thor
8
- desc "start", "start notifier"
9
- def start
9
+ PLIST_NAME = "arkadiybutermanov.co2-notify".freeze
10
+
11
+ desc "go", "start notifier"
12
+ def go
10
13
  Notifier.start
11
14
  end
12
15
 
16
+ desc "start", "start notifier in background"
17
+ def start
18
+ system "launchctl load #{plist_path}"
19
+ end
20
+
21
+ desc "stop", "stop background notifier"
22
+ def stop
23
+ system "launchctl unload #{plist_path}"
24
+ end
25
+
13
26
  desc "init", "setup config"
14
27
  def init
15
28
  Config.set
16
29
  end
17
30
 
18
31
  desc "autoload", "setup OSX plist"
19
- def autoload
20
- plist_path = File.expand_path("arkadiybutermanov.co2-notify.plist", __dir__)
21
- target_path = File.expand_path("Library/LaunchAgents", ENV["HOME"])
32
+ def autoload(path)
33
+ data = {
34
+ "KeepAlive" => true,
35
+ "Label" => PLIST_NAME,
36
+ "ProgramArguments" => [
37
+ path,
38
+ "go"
39
+ ],
40
+ "RunAtLoad" => true
41
+ }
42
+
43
+ File.open(plist_path, "w") do |f|
44
+ f.write Plist::Emit.dump(data)
45
+ end
46
+ end
47
+
48
+ private
22
49
 
23
- FileUtils.cp plist_path, target_path
50
+ def plist_path
51
+ File.expand_path("Library/LaunchAgents/#{PLIST_NAME}.plist", ENV["HOME"])
24
52
  end
25
53
  end
26
54
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: co2-notify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkadiy Butermanov
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: plist
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description:
70
84
  email:
71
85
  - arkadiy.butermanov@flatstack.com
@@ -80,7 +94,6 @@ files:
80
94
  - Rakefile
81
95
  - bin/co2-notify
82
96
  - co2-notify.gemspec
83
- - lib/arkadiybutermanov.co2-notify.plist
84
97
  - lib/co2-notify.rb
85
98
  - lib/co2-notify/config.rb
86
99
  - lib/co2-notify/hipchat_client.rb
@@ -1,17 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>KeepAlive</key>
6
- <true/>
7
- <key>Label</key>
8
- <string>arkadiybutermanov.co2-notify</string>
9
- <key>ProgramArguments</key>
10
- <array>
11
- <string>/usr/local/var/rbenv/shims/co2-notify</string>
12
- <string>start</string>
13
- </array>
14
- <key>RunAtLoad</key>
15
- <true/>
16
- </dict>
17
- </plist>