Skip to content

Commit

Permalink
release prep
Browse files Browse the repository at this point in the history
  • Loading branch information
ttscoff committed Jul 22, 2021
1 parent 523a234 commit 15c9999
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.0.64

- Initial import feature for Timing.app reports

### 1.0.63

- README updates
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ _Side note:_ I actually use the library behind this utility as part of another s

## Installation

The current version of `doing` is <!--VER-->1.0.62<!--END VER-->.
The current version of `doing` is <!--VER-->1.0.63<!--END VER-->.

$ [sudo] gem install doing

Expand Down
35 changes: 35 additions & 0 deletions bin/doing
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,41 @@ command :undo do |c|
end
end

desc 'Import entries from an external source'
long_desc 'Imports entries from other sources. Currently only handles JSON reports exported from Timing.app.'
arg_name 'PATH'
command [:import] do |c|
c.desc 'Import type'
c.arg_name 'TYPE'
c.flag [:type], default_value: 'timing'

c.desc 'Target section'
c.arg_name 'NAME'
c.flag %i[s section], default_value: wwid.current_section

c.desc 'Tag all imported entries'
c.arg_name 'TAGS'
c.flag [:tag]

c.desc 'Prefix entries with'
c.arg_name 'PREFIX'
c.flag [:prefix]

c.action do |_global_options, options, args|

section = wwid.guess_section(options[:s]) || options[:s].cap_first

if options[:type] =~ /^tim/i
args.each do |path|
wwid.import_timing(path, { section: section, tag: options[:tag], prefix: options[:prefix] })
wwid.write(wwid.doing_file)
end
else
raise 'Invalid import type'
end
end
end

pre do |global, _command, _options, _args|
if global[:config_file] && global[:config_file] != wwid.config_file
wwid.config_file = global[:config_file]
Expand Down
2 changes: 1 addition & 1 deletion lib/doing/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Doing
VERSION = '1.0.63'
VERSION = '1.0.64'
end
51 changes: 50 additions & 1 deletion lib/doing/wwid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def init_doing_file(path = nil)
else
@content[section]['items'][current - 1]['note'] = [] unless @content[section]['items'][current - 1].key? 'note'

@content[section]['items'][current - 1]['note'].push(line.gsub(/ *$/, ''))
@content[section]['items'][current - 1]['note'].push(line.chomp)
# end
end
end
Expand Down Expand Up @@ -667,6 +667,55 @@ def add_item(title, section = nil, opt = {})
@results.push(%(Added "#{entry['title']}" to #{section}))
end

##
## @brief Imports a Timing report
##
## @param path (String) Path to JSON report file
## @param section (String) The section to add to
## @param opt (Hash) Additional Options
##
def import_timing(path, opt = {})
section = opt[:section] || @current_section
add_section(section) unless @content.has_key?(section)

add_tags = opt[:tag] ? opt[:tag].split(/[ ,]+/).map { |t| t.sub(/^@?/, '@') }.join(' ') : ''
prefix = opt[:prefix] ? opt[:prefix] : '[Timing.app]'
raise "File not found" unless File.exist?(File.expand_path(path))

data = JSON.parse(IO.read(File.expand_path(path)))
new_items = []
data.each do |entry|
# Only process task entries
next if entry.key?('activityType') && entry['activityType'] != 'Task'
# Only process entries with a start and end date
next unless entry.key?('startDate') && entry.key?('endDate')

start_time = Time.parse(entry['startDate'])
end_time = Time.parse(entry['endDate'])
next unless start_time && end_time
tags = entry['project'].split(/ ▸ /).map {|proj| proj.gsub(/ +/, '').downcase }
title = "#{prefix} "
title += entry.key?('activityTitle') && entry['activityTitle'] != '(Untitled Task)' ? entry['activityTitle'] : 'Working on'
tags.each do |tag|
if title =~ /\b#{tag}\b/i
title.sub!(/\b#{tag}\b/i, "@#{tag}")
else
title += " @#{tag}"
end
end
title = autotag(title) if @auto_tag
title += " @done(#{end_time.strftime('%Y-%m-%d %H:%M')})"
title.gsub!(/ +/, ' ')
title.strip!
new_entry = { 'title' => title, 'date' => start_time, 'section' => section }
new_entry['note'] = entry['notes'].split(/\n/).map(&:chomp) if entry.key?('notes')
new_items.push(new_entry)
end

@content[section]['items'].concat(new_items)
@results.push(%(Imported #{new_items.count} items to #{section}))
end

##
## @brief Return the content of the last note for a given section
##
Expand Down

0 comments on commit 15c9999

Please sign in to comment.