Last active
October 10, 2015 01:37
-
-
Save pdxmph/3611624 to your computer and use it in GitHub Desktop.
Gather Evernote notes, flagged mail and recent bookmarks.
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 | |
| require "rubygems" | |
| require "appscript" | |
| include Appscript | |
| require "active_support" | |
| require "rss/1.0" | |
| require "rss/2.0" | |
| require "open-uri" | |
| require "bitly" | |
| require "cgi" | |
| require "ftools" | |
| tsf = "/Users/mike/.panopticon_stamp" | |
| timestamp = File.stat(tsf).mtime | |
| @look_back = (Time.now - timestamp) | |
| @things = app("Things") | |
| @todos = @things.to_dos | |
| # define source apps | |
| @mail = app("Mail") | |
| @nnw = app("NetNewsWire") | |
| @evernote = app("Evernote") | |
| def create_to_do(name,source,link,tags) | |
| unless @todos[its.name.eq(name)].get.length > 0 | |
| puts "Didn't find a thing named #{name}. Creating a task." | |
| if link == "" | |
| note = name | |
| else | |
| note = "[url=#{link}]#{name} - #{source}[/url]" | |
| end | |
| task = @things.make(:at => app.lists["Inbox"].beginning, :new => :to_do, :with_properties => { | |
| :name => name, | |
| :tag_names => tags, | |
| :notes => note, | |
| }) | |
| end | |
| end | |
| # handle mail stuff | |
| puts "Checking mail ..." | |
| accounts = { | |
| "Both Pieces" => "INBOX", | |
| "Gmail" => "INBOX", | |
| "Exchange" => "INBOX"} | |
| accounts.each do |acct,box| | |
| account = @mail.accounts[acct].get | |
| inbox = account.mailboxes[box].get | |
| messages = inbox.messages[its.flagged_status.eq(true).and( | |
| its.date_received.gt(Time.now - @look_back) | |
| )].get | |
| messages.each do |m| | |
| message_id = m.message_id.get | |
| message_link = "message:%3C#{message_id}%3E" | |
| create_to_do("#{m.subject.get.strip}: #{m.sender.get.strip} (#{acct})","mail",message_link,"panopticon,mail") | |
| end | |
| end | |
| # handle NetNewsWire flagged items | |
| puts "Checking feeds ..." | |
| subs = @nnw.subscriptions[its.display_name.eq('Flagged Items')].first.get | |
| subs.headlines.get.each do |h| | |
| if h.date_arrived.get > Time.now - @look_back | |
| create_to_do(h.title.get.strip,"RSS",h.permalink.get,"panopticon,readable,rss") | |
| h.isFlagged.set(:no) | |
| end | |
| end | |
| # handle Instapaper subscriptions | |
| puts "Checking InstaPaper ..." | |
| content = "" | |
| instapaper_feed = "your_instapaper_feed" | |
| open(instapaper_feed) do |s| | |
| content = s.read | |
| end | |
| rss = RSS::Parser.parse(content, false) | |
| rss.items.each do |i| | |
| if i.pubDate > (Time.now - @look_back) | |
| link = CGI::escape(i.link) | |
| url = "http://www.instapaper.com/m?u=#{link}" | |
| create_to_do(i.title.strip,"Instapaper",url,"panopticon,readable,rss") | |
| end | |
| end | |
| # handle Evernote stuff | |
| puts "Checking Evernote ..." | |
| notes = @evernote.notebooks["Inbox"].notes[its.creation_date.gt(Time.now - @look_back)].get | |
| notes.each do |n| | |
| create_to_do(n.title.get.strip, "Evernote","","panopticon,evernote") | |
| end | |
| # handle delicious bookmarks | |
| puts "Checking delicious ..." | |
| content = "" | |
| delicious_feed = "http://feeds.delicious.com/v2/rss/your_user_name" | |
| open(delicious_feed) do |s| | |
| content = s.read | |
| end | |
| rss = RSS::Parser.parse(content, false) | |
| rss.items.each do |i| | |
| if i.pubDate > (Time.now - @look_back) | |
| create_to_do(i.title.strip,"delicious",i.link,"panopticon,readable,delicious") | |
| end | |
| end | |
| `touch #{tsf}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment