Skip to content

Instantly share code, notes, and snippets.

@pawelniewie
Last active August 24, 2016 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawelniewie/eeec1d0ed9b289985e623a20cc9ce71b to your computer and use it in GitHub Desktop.
Save pawelniewie/eeec1d0ed9b289985e623a20cc9ce71b to your computer and use it in GitHub Desktop.
#!/bin/env ruby
require 'json'
require 'time'
cutoff = Time.parse('2016-08-10')
log = JSON.load(ARGF)
entries_per_day = Hash.new{ |hash, key| hash[key] = [] }
(log['entries'].
select { |e| Time.parse(e['creationDate']) > cutoff }.
reverse.
reduce (entries_per_day) { |memo, e| memo[Time.parse(e['creationDate']).strftime('%F')] << e; memo }).
each_pair { |date, entries|
puts
puts date
entries.
sort { |x, y| Time.parse(x['creationDate']) <=> Time.parse(y['creationDate']) }.
each { |e| puts Time.parse(e['creationDate']).strftime('%R') + ' ' + e['text']}
}
@pawelniewie
Copy link
Author

Simple script that will print out entries from Day One JSON dump.

Sample output:

2016-08-12
21:58 text
21:58 another

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment