-
-
Save maxjacobson/1b72ae7fe658ca8bd60b to your computer and use it in GitHub Desktop.
script to print your overdue Due (http://www.dueapp.com/) reminders on Linux
This file contains hidden or 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 | |
| # standard libraries | |
| require 'fileutils' | |
| require 'securerandom' | |
| require 'logger' | |
| # external library -- run `gem install oga` before this script will work | |
| require 'oga' | |
| # also: `sudo apt-get install libplist-utils` is necessary | |
| # (this is a Linux thing. If you're on a Mac just get the Mac app :)) | |
| # print updates if run with `LOG=true due` | |
| logger = Logger.new(STDOUT) | |
| logger.level = ENV['LOG'] ? Logger::INFO : Logger::ERROR | |
| path_to_due_sync_file = File.expand_path "~/Dropbox/Apps/Due App/Sync.dueappgz" | |
| unless File.exist?(path_to_due_sync_file) | |
| raise 'no bueno' | |
| end | |
| unless Dir.exist?("/tmp") | |
| raise 'no bueno' | |
| end | |
| logger.info "copying the db to tmp" | |
| # copy to a temp file, reclassify as tgz for the benefit of gunzip | |
| copy_path = File.expand_path("/tmp/duesync-#{SecureRandom.hex}.tgz") | |
| FileUtils.cp(path_to_due_sync_file, copy_path) | |
| logger.info "changing directory to tmp" | |
| FileUtils.chdir("/tmp") | |
| logger.info "unzipping the db" | |
| # converts the tgz to a tar, which plistutils can read | |
| `gunzip #{copy_path}` | |
| unless $?.success? | |
| logger.error "failed to unzip" | |
| exit 1 | |
| end | |
| logger.info "converting binary plist to xml" | |
| expected_tar_path = copy_path.gsub("tgz", "tar") | |
| xml_path = copy_path.gsub("tgz", "xml") | |
| `plistutil -i #{expected_tar_path} -o #{xml_path} --debug` | |
| unless $?.success? | |
| logger.error "failed" | |
| exit 1 | |
| end | |
| logger.info "parsing the xml with oga" | |
| xml = Oga.parse_xml(File.read(xml_path), strict: true) | |
| logger.info "done parsing" | |
| logger.info "extracting information from the xml" | |
| class DueReporter | |
| def initialize(xml) | |
| @xml = xml | |
| end | |
| # returns array of string messages | |
| # note: | |
| # "2" status means overdue reminders | |
| # "1" status means upcoming reminders | |
| # "0" status means timers | |
| # some random other numeric string means all of your "logged" reminders | |
| def results | |
| xml.xpath("//key[text()='status']") | |
| .select { |status| ["2"].include?(status.next_element.text) } | |
| .map { |status| | |
| "#{reminder_text(status.parent)} #{due_date(status.parent)}" | |
| }.reverse | |
| end | |
| private | |
| attr_reader :xml | |
| def reminder_text(reminder) | |
| reminder.next_element.text | |
| end | |
| # TODO: make this work :) | |
| # right now it prints out some inscrutable number. The number must mean | |
| # something... but what? | |
| def due_date(reminder) | |
| due_date_key = reminder.xpath("key[text()='dateDue']").first.next_element.css("integer").text | |
| # dict = xml.xpath("//key[text()='NS.time']").detect do |time| | |
| # time.parent.css("integer").text == due_date_key | |
| # end | |
| # raise 'no matching time' if dict.nil? | |
| # real = dict.css("real").text | |
| # time = Time.at(real.to_f) | |
| # "???" | |
| "(#{due_date_key})" | |
| end | |
| end | |
| results = DueReporter.new(xml).results | |
| logger.info "done extracting" | |
| puts results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After some experimentation, I'm pretty certain it represents seconds since Jan 1, 2000