Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How many things have I done today, according to the Things app?
require 'sqlite3'
require 'rubygems'
`cp ThingsLibrary.db ThingsLibrary_cache.db`
db = SQLite3::Database.new("ThingsLibrary_cache.db")
db.results_as_hash = true
row = db.get_first_row( "SELECT count(ZTHING.Z_PK) as today FROM ZTHING LEFT OUTER JOIN ZTHING PROJECT on ZTHING.ZPROJECT = PROJECT.Z_PK LEFT OUTER JOIN ZTHING AREA on ZTHING.ZAREA = AREA.Z_PK WHERE ZTHING.ZSTARTDATE != '' and ZTHING.ZSTATUS != 3 and ZTHING.ZSTATUS != 2 and ZTHING.ZTRASHED = 0 and ZTHING.ZSTART = 1 ORDER BY ZTHING.ZTODAYINDEX;" )
today = row['today']
row = db.get_first_row( "SELECT date(ZSTOPPEDDATE, 'unixepoch', '+31 years', 'localtime') as date, count(Z_PK) as completed from ZTHING WHERE ZSTATUS = 3 and date = (SELECT date('now')); " )
completed = row['completed']
row = db.get_first_row( "SELECT date(ZCREATIONDATE, 'unixepoch', '+31 years', 'localtime') as date, count(Z_PK) as created FROM ZTHING WHERE ZCREATIONDATE != '' and date = (SELECT date('now')); " )
created = row['created']
total = completed + today
percent = completed.to_f / total * 100
puts " #{percent.round}% (#{completed} / #{today})"
puts " Completed: #{completed}"
puts " Due today: #{today}"
puts " Created today: #{created}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.