Created
November 5, 2012 22:18
-
-
Save jimweirich/4020776 to your computer and use it in GitHub Desktop.
Data Havesters for twitter names
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 'open-uri' | |
| require 'json' | |
| # Note: Some of these haven't filled out the who's who page yet | |
| MISSING = %w(codingbull ericries flngn giffco JeetKunDoug Joi kattrali kEND rabble tappythebird) | |
| updating = ARGV.include?("--update") | |
| class TwitterList | |
| def initialize(name) | |
| @name = name | |
| end | |
| def current_members | |
| @members ||= `t list members new-context`.split(/\n/) | |
| end | |
| def add_members(members) | |
| system "t list add #@name #{members.join(' ')}" unless members.empty? | |
| end | |
| def remove_members(members) | |
| system "t list remove #@name #{members.join(' ')}" unless members.empty? | |
| end | |
| end | |
| def get_page(url) | |
| open(url, :http_basic_authentication => ["USER ELIDED", "PASSWORD ELIDED"]) { |f| f.read } | |
| end | |
| def empty?(handle) | |
| handle.nil? || handle =~ /^ *$/ | |
| end | |
| def normalize(handle) | |
| if empty?(handle) | |
| nil | |
| else | |
| handle.sub(/^@/,'').sub(/^https?:.*\//, '') | |
| end | |
| end | |
| json = get_page("http://ELIDED/data.json") | |
| data = JSON.parse(json) | |
| twitter_handles = data.map { |who| normalize(who["twitter"]) }.compact.sort | |
| all_handles = (twitter_handles + MISSING).sort.uniq | |
| list = TwitterList.new("new-context") | |
| to_add = all_handles - list.current_members | |
| to_remove = list.current_members - all_handles | |
| puts "Adding: #{to_add.join(' ')}" | |
| list.add_members(to_add) if updating | |
| puts "Removing: #{to_remove.join(' ')}" | |
| list.remove_members(to_remove) if updating | |
| found = twitter_handles & MISSING | |
| puts "No longer missing: #{found.join(' ')}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment