Skip to content

Instantly share code, notes, and snippets.

@rooreynolds
Created January 4, 2017 21:58
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 rooreynolds/1e68cde913998052e76a979e37744396 to your computer and use it in GitHub Desktop.
Save rooreynolds/1e68cde913998052e76a979e37744396 to your computer and use it in GitHub Desktop.
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