Created
February 14, 2011 22:07
-
-
Save rcanand/826669 to your computer and use it in GitHub Desktop.
Extracts and shows links from gmail and safari bookmarks
This file contains 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/ruby | |
require 'rubygems' | |
require 'gmail' | |
require 'nokogiri' | |
# Script to extract and show links from gmail and safari bookmarks | |
def parse_for_links s | |
results = [] | |
url = /( |^)http:\/\/([^\s]*\.[^\s]*)( |$)/ | |
s.scan(url) do |match| | |
puts match | |
end | |
end | |
all_links = [] | |
def get_gmail_links u, p | |
gmail_links = [] | |
gmail = Gmail.new(u,p) | |
gmail.inbox.emails(:from => u).each do |email| | |
if(email.parts && email.parts.count>0) | |
email.parts.each do |part| | |
message = part.to_s | |
#gmail_links << | |
parse_for_links(message) | |
end | |
end | |
end | |
gmail.logout | |
gmail_links | |
end | |
def get_safari_links | |
# change path of output file as needed in next two lines | |
`plutil -convert xml1 -o /tmp/SafariBookmarks.xml ~/Library/Safari/Bookmarks.plist` | |
doc = Nokogiri::XML.parse(open('/tmp/SafariBookmarks.xml')) | |
doc.xpath("//string").each{|v| puts v.content if (!v.content.nil? && v.content.start_with?('http'))} | |
end | |
def get_all_links | |
all_links = [] | |
all_links << get_safari_links | |
# change username and password as shown below | |
all_links << get_gmail_links('[email protected]', 'password') | |
all_links.uniq | |
end | |
get_all_links.each do |link| | |
puts link | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment