This repository has been archived by the owner on Jan 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
doing.rb
62 lines (53 loc) · 1.83 KB
/
doing.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
=begin
Plugin: doing yesterday logger
Version: 0.1
Description: Logs output for doing yesterday --totals
Author: [soleblaze](https://github.com/soleblaze)
Configuration:
doing_tags: #doing
Notes:
=end
config = {
'description' => ['doing plugin',
'Adds doing yesterday to dayone' ],
'doing_tags' => '#doing'
}
$slog.register_plugin({ 'class' => 'DoingLogger', 'config' => config })
class DoingLogger < Slogger
def do_log
if @config.key?(self.class.name)
config = @config[self.class.name]
else
@log.warn("Doing has not been configured.")
return
end
@log.info("Logging doing time tracking for yesterday")
tags = config['doing_tags'] || ''
tags = "\n\n#{tags}\n" unless @tags == ''
output = %x{~/bin/doing yesterday --totals}
# Perform necessary functions to retrieve posts
# create an options array to pass to 'to_dayone'
# all options have default fallbacks, so you only need to create the options
# you want to specify
options = {}
options['content'] = "## Doing Yesterday\n\n#{output}#{tags}"
options['datestamp'] = Time.now.utc.iso8601
options['starred'] = true
options['uuid'] = %x{uuidgen}.gsub(/-/,'').strip
# Create a journal entry
# to_dayone accepts all of the above options as a hash
# generates an entry base on the datestamp key or defaults to "now"
unless output.nil? or output == "\n\n"
sl = DayOne.new
sl.to_dayone(options)
end
# To create an image entry, use `sl.to_dayone(options) if
# sl.save_image(imageurl,options['uuid'])`
# save_image takes an image path and a uuid that must be identical the one
# passed to to_dayone
# save_image returns false if there's an error
end
def helper_function(args)
# add helper functions within the class to handle repetitive tasks
end
end