Posted By

pdxmph on 07/04/10


Tagged

ruby delicious things Appscript netnewswire instapaper


Versions (?)

Panopticon


 / Published in: Ruby
 

  1. #!/usr/bin/env ruby
  2.  
  3. require "rubygems"
  4. require "appscript"
  5. include Appscript
  6. require "active_support"
  7. require 'rss/1.0'
  8. require 'rss/2.0'
  9. require 'open-uri'
  10.  
  11. @mail = app("Mail")
  12. @things = app("Things")
  13. @nnw = app("NetNewsWire")
  14. @evernote = app("Evernote")
  15.  
  16. def create_to_do(name,notes,source)
  17. unless @things.lists["Today"].to_dos[its.name.eq(name)].get.length > 0
  18. puts "Didn't find a thing named #{name}. Creating a task."
  19. task = @things.make(:at => app.lists["Today"].beginning, :new => :to_do, :with_properties => {
  20. :name => name,
  21. :tag_names => "panopticon,#{source}",
  22. :notes => notes,
  23. :due_date => Time.now + 8.hours
  24. })
  25. else
  26. puts "I found a thing with the name '#{name}', not creating a task."
  27. end
  28. end
  29.  
  30. # handle mail stuff
  31. accounts = {"Personal" => "INBOX",
  32. "Both Pieces IMAP" => "INBOX",
  33. "Exchange" => "INBOX"}
  34.  
  35. accounts.each do |acct,box|
  36. account = @mail.accounts[acct].get
  37.  
  38. inbox = account.mailboxes[box].get
  39.  
  40. messages = inbox.messages[its.flagged_status.eq(true).and(
  41. its.date_received.gt(Time.now - 2.days)
  42. )].get
  43.  
  44. messages.each do |m|
  45. create_to_do("#{m.subject.get} - #{m.sender.get} (#{acct})","", "mail")
  46. end
  47. end
  48.  
  49. # handle NetNewsWire flagged items
  50.  
  51. subs = @nnw.subscriptions[its.display_name.eq('Flagged Items')].first.get
  52.  
  53. subs.headlines.get.each do |h|
  54. if h.date_arrived.get > Date.today - 2.days
  55. create_to_do(h.title.get,"","RSS")
  56. end
  57. end
  58.  
  59. # handle Instapaper subscriptions
  60. content = ""
  61. instapaper_feed = "http://www.instapaper.com/rss/..."
  62.  
  63. open(instapaper_feed) do |s|
  64. content = s.read
  65. end
  66.  
  67. rss = RSS::Parser.parse(content, false)
  68.  
  69. rss.items.each do |i|
  70. if i.pubDate > (Time.now - 2.days)
  71. create_to_do(i.title,"","Instapaper")
  72. end
  73. end
  74.  
  75. # handle Evernote stuff
  76.  
  77. notes = @evernote.notebooks["Inbox"].notes[its.creation_date.gt(Time.now - 2.days)].get
  78.  
  79. notes.each do |n|
  80. create_to_do(n.title.get, "", "Evernote")
  81. end

Report this snippet  

You need to login to post a comment.