Skip to content

Instantly share code, notes, and snippets.

@aaronmoodie
Last active July 13, 2021 09:57
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 aaronmoodie/47cb0998d10ff6c824d547df2050bd7b to your computer and use it in GitHub Desktop.
Save aaronmoodie/47cb0998d10ff6c824d547df2050bd7b to your computer and use it in GitHub Desktop.
# Generate stats for journal files
require 'date'
stats = {
total_files: 0,
word_count: 0,
late_entry: 0,
}
journal_dir = "<journal dir here>"
Dir.glob("#{journal_dir}/*.md") do |filename|
# create datetime from file name
file_date = DateTime.parse(filename.delete_suffix('.md'))
# Skip file if before July 14th 2020
next if file_date < DateTime.new(2020,7,14)
# Get file created datetime
file_created_date = File.stat(filename).birthtime
stats[:total_files] += 1
stats[:late_entry] += 1 if file_date.day != file_created_date.day
File.open(filename, "r").each_line do |line|
words = line.split(/\s+/).reject{ |w| w.empty? }
stats[:word_count] += words.length
end
end
puts "Total word count: #{stats[:word_count]}"
puts "Total entries: #{stats[:total_files]}"
puts "Late entries: #{stats[:late_entry]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment