Created
May 11, 2010 20:26
-
-
Save Govan/397820 to your computer and use it in GitHub Desktop.
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
# | |
# Assuming your address book entries have a URL field 'twitter' containing either their full Twitter URL, or just | |
# their username, go fetch the image and drop it into the addressbook. | |
# | |
# Works for me, but your milage may vary. | |
# | |
require 'rubygems' | |
require 'twitter' | |
require 'open-uri' | |
require 'fileutils' | |
require 'appscript' | |
include Appscript | |
httpauth = Twitter::HTTPAuth.new('USERNAME', 'PASSWORD') | |
client = Twitter::Base.new(httpauth) | |
address_book_image_dir = File.expand_path("~/Library/Application Support/AddressBook/Images/") | |
app("Address Book").people.get.each do |person| | |
person.urls.get.each do |url| | |
if 'twitter' == (url.label.get.downcase) | |
puts "Updating avatar for #{person.name.get}" | |
twitter_url = url.value.get | |
twitter_id = twitter_url.split("/").last | |
friend = client.user(twitter_id) | |
twitter_avatar = friend.profile_image_url.gsub(/_normal(\.[a-zA-Z]+)$/, '_bigger\1') | |
new_image = File.join(address_book_image_dir, person.id_.get.split(':')[0]) | |
File.open(new_image, 'w+') { |f| f.write open(twitter_avatar).read } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment