Skip to content

Instantly share code, notes, and snippets.

@pauldruziak
Created November 24, 2010 03:49
Show Gist options
  • Save pauldruziak/713077 to your computer and use it in GitHub Desktop.
Save pauldruziak/713077 to your computer and use it in GitHub Desktop.
Выводит список задач с файлика приложения Things
require 'rubygems'
require 'nokogiri'
@doc = Nokogiri::XML(File.open("Database.xml"))
nodes = @doc.xpath("//object[@type='TODO']")
projects = {"0" => {"todos" => [], "title" => 'NEXT'}}
nodes.each do |node|
todo = {}
node.children.each do |attr|
if attr["name"] == 'parent' && !attr["idrefs"].nil?
todo["parent"] = attr["idrefs"]
else
todo[attr["name"]] = attr.text
end
end
if (todo["focuslevel"].to_i == 1 or todo["focuslevel"].to_i == 2) && todo["status"].to_i # Проект или область действия
projects[node["id"]] ||= {}
projects[node["id"]].merge!(todo)
projects[node["id"]]["todos"] ||= []
end
if todo["focuslevel"].to_i == 0 && todo["status"].to_i == 0 # Задача
unless todo.include?("parent") || !todo["parent"].empty?
todo["parent"] = "0"
end
unless projects.include?(todo["parent"])
projects[todo["parent"]] = {"todos" => []}
end
projects[todo["parent"]]["todos"] << todo
end
end
projects.each do |id, attr|
unless attr["todos"].empty?
puts '===================================================================================================================='
puts attr["title"]
puts '--------------------------------------------------------------------------------------------------------------------'
attr["todos"].each do |attr|
hrefs = attr["content"].scan /http:\/\/[a-zA-Z0-9\/\._-]*/ if attr["content"]
puts "- #{attr["title"]}"
hrefs.each do |href|
puts " => #{href}"
end unless hrefs.nil? || hrefs.empty?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment