dnotify 0.0.1
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/.gitignore +4 -0
- data/Gemfile +6 -0
- data/README.md +20 -0
- data/Rakefile +2 -0
- data/bin/dnotify +11 -0
- data/dnotify.gemspec +24 -0
- data/lib/dnotify/version.rb +3 -0
- data/lib/dnotify.rb +81 -0
- data/resources/clock.png +0 -0
- data/resources/dnotifyrc.sample.yaml +5 -0
- metadata +87 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
dnotify
|
2
|
+
=======
|
3
|
+
|
4
|
+
This is a simple gem which allows you to setup reminders using a simple yaml file allowing you to use natural language. Run the following commands to set it up:
|
5
|
+
|
6
|
+
gem install dnotify
|
7
|
+
dnotify setup
|
8
|
+
|
9
|
+
Add your reminders to ~/.dnotifyrc
|
10
|
+
|
11
|
+
#~/.dnotifyrc
|
12
|
+
---
|
13
|
+
- :summary: Time to play badminton
|
14
|
+
:time: 10:27 in the evening
|
15
|
+
- :summary: Time to reminisce
|
16
|
+
:time: 9 in the evening saturday
|
17
|
+
- :summary: Call it a day
|
18
|
+
:time: 10:28 in the evening
|
19
|
+
|
20
|
+
Enjoy!
|
data/Rakefile
ADDED
data/bin/dnotify
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../lib/dnotify')
|
4
|
+
|
5
|
+
if ARGV.count > 0 && ARGV[0] =~ /(setup)/i
|
6
|
+
puts 'setting up dnotify'
|
7
|
+
Dnotify::Setup.run
|
8
|
+
else
|
9
|
+
puts 'running dnotify'
|
10
|
+
Dnotify::Notifier.new.run
|
11
|
+
end
|
data/dnotify.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "dnotify/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "dnotify"
|
7
|
+
s.version = Dnotify::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Khaja Minhajuddin"]
|
10
|
+
s.email = ["minhajuddin.k@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/minhajuddin/dnotify"
|
12
|
+
s.summary = %q{Allows you to setup passive reminders for stuff}
|
13
|
+
s.description = %q{Allows you to setup passive reminders using natural language}
|
14
|
+
|
15
|
+
s.rubyforge_project = "dnotify"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'chronic', '~> 0.4'
|
23
|
+
s.add_dependency 'libnotify', '~> 0.5'
|
24
|
+
end
|
data/lib/dnotify.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
module Dnotify
|
2
|
+
class Setup
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
ConfigPath = File.expand_path "~/.dnotifyrc"
|
7
|
+
|
8
|
+
def self.run
|
9
|
+
setup unless check
|
10
|
+
write_crontab
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.setup
|
14
|
+
FileUtils.cp(File.join(File.dirname(__FILE__), '../resources/dnotifyrc.sample.yaml'), ConfigPath)
|
15
|
+
puts "copied default template to #{ConfigPath}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.write_crontab
|
19
|
+
existing_crontab = `crontab -l`
|
20
|
+
return if existing_crontab =~ /dnotify/i
|
21
|
+
#copied from https://github.com/javan/whenever/blob/master/lib/whenever/command_line.rb
|
22
|
+
puts 'setting up cron'
|
23
|
+
tmp_cron_file = Tempfile.new('dnotify_tmp_cron').path
|
24
|
+
File.open(tmp_cron_file, File::WRONLY | File::APPEND) do |file|
|
25
|
+
file << existing_crontab << "* * * * * /bin/bash -l -c 'dnotify' >> /tmp/dnotify.log\n"
|
26
|
+
end
|
27
|
+
puts `crontab #{tmp_cron_file}`
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.check
|
31
|
+
config_present = File.exists?(ConfigPath)
|
32
|
+
if config_present
|
33
|
+
puts 'dnotify is setup'
|
34
|
+
else
|
35
|
+
puts "no config file(#{ Setup::ConfigPath }) exists"
|
36
|
+
end
|
37
|
+
config_present
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
class Notifier
|
43
|
+
require 'yaml'
|
44
|
+
require 'chronic'
|
45
|
+
require 'libnotify'
|
46
|
+
|
47
|
+
DefaultNotification = {:body => "Alarm", :summary => "Alarm", :timeout => 2.5, :icon_path => File.join(File.dirname(__FILE__),'../resources/clock.png') }
|
48
|
+
|
49
|
+
def run
|
50
|
+
return unless Setup.check
|
51
|
+
#check if a reminder aligns with the current time
|
52
|
+
reminders.each do |reminder|
|
53
|
+
notify(reminder) if trigger?(reminder)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def notify(reminder)
|
58
|
+
Libnotify.show(DefaultNotification.merge(reminder))
|
59
|
+
end
|
60
|
+
|
61
|
+
def trigger?(reminder)
|
62
|
+
reminder_time = Chronic.parse(reminder[:time], :context => :past)
|
63
|
+
now = Time.now.floor
|
64
|
+
reminder_time == now
|
65
|
+
end
|
66
|
+
|
67
|
+
def reminders
|
68
|
+
@reminders ||= YAML::load_file(Setup::ConfigPath)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Time
|
74
|
+
def round(seconds = 60)
|
75
|
+
Time.at((self.to_f / seconds).round * seconds)
|
76
|
+
end
|
77
|
+
|
78
|
+
def floor(seconds = 60)
|
79
|
+
Time.at((self.to_f / seconds).floor * seconds)
|
80
|
+
end
|
81
|
+
end
|
data/resources/clock.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dnotify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Khaja Minhajuddin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-12 00:00:00 +05:30
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: chronic
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0.4"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: libnotify
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0.5"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
description: Allows you to setup passive reminders using natural language
|
39
|
+
email:
|
40
|
+
- minhajuddin.k@gmail.com
|
41
|
+
executables:
|
42
|
+
- dnotify
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- bin/dnotify
|
53
|
+
- dnotify.gemspec
|
54
|
+
- lib/dnotify.rb
|
55
|
+
- lib/dnotify/version.rb
|
56
|
+
- resources/clock.png
|
57
|
+
- resources/dnotifyrc.sample.yaml
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: https://github.com/minhajuddin/dnotify
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project: dnotify
|
82
|
+
rubygems_version: 1.5.0
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Allows you to setup passive reminders for stuff
|
86
|
+
test_files: []
|
87
|
+
|