Last active
December 23, 2015 04:59
-
-
Save craigeley/6583530 to your computer and use it in GitHub Desktop.
Scans a folder for writing files and updates an HTML file stored in Dropbox which can be read by Status Board
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# sb-writing.rb - Monitor Daily Writing Progress with Status Board | |
# by Craig Eley <http://craigeley.com> | @craigeley | |
# Based loosely on tp-dailylog.rb by Brett Terpstra <https://gist.github.com/ttscoff/1913007> | |
# Finds files modified in the last day from a specific folder | |
# Sends modification time, title, and word count to an HTML file in a Dropbox Folder | |
# Add the path to your files on line 13 | |
# Add path to Dropbox and name your HTML file on line 41 | |
# Includes a pencil icon as an image; feel free to adjust in line 25 | |
# Use Lingon or Hazel to set it to run at an interval or when files change | |
files = Dir["/Users/USERNAME/Path/To/Writing/*/*.txt"].select { |fname| File.mtime(fname) > (Time.now - 86400) }.sort_by!{ |f| File.mtime(f) }.reverse! | |
projects = [] | |
files.each do |file| | |
f = File.open(file.strip, encoding: 'UTF-8') | |
lines = f.readlines | |
mod = f.mtime | |
modtime = f.mtime.strftime("%I:%M%p") | |
text = lines.join | |
wordcount = text.split.length | |
title = File.basename(file).gsub(/.txt/, ' ').strip | |
if mod > (Time.now - 86400) | |
found_completed = true | |
project = "<td class=\"projectIcon\"><img src=\"http://chadwrightcreative.com/wp-content/uploads/2011/01/CWC_Writing_Icon1.png\" /></td>" + "\n" + "<td class=\"Last Modified\" style=\"width: 156px\">#{modtime}</td>" + "\n" + "<td class=\"projectName\" style=\"width: 487px\">#{title}</td>" + "\n" + "<td class=\"Word Count\">#{wordcount} words</td>" + "\n" + "</td>" + "\n" + "</tr>" +"\n" | |
end | |
if found_completed | |
projects.push(project) | |
end | |
end | |
def e_sh(str) | |
str.to_s.gsub(/(?=["\\])/, '\\') | |
end | |
if projects.length > 0 | |
entrytext = "<table id=\"projects\">\n<table style= font-size:0.8em>\n" | |
projects.each do |project| | |
entrytext += project | |
end | |
open('/Users/USERNAME/Dropbox/StatusBoard/Panic.html', 'w') { |f| | |
f.puts "#{entrytext}" + "</table>"} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment