Skip to content

Instantly share code, notes, and snippets.

@kayakaya
Created January 18, 2010 16:59
Show Gist options
  • Save kayakaya/280180 to your computer and use it in GitHub Desktop.
Save kayakaya/280180 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'rubytter'
require 'yaml'
require 'pit'
require 'pp'
def toCsv(friends)
open('friends.csv', 'w') do |f|
friends.each do |user|
f.puts "#{user.screen_name},#{user.id}, #{user.name}, #{user.description.to_s.gsub(/\r\n/,'')}"
end
end
end
def toYaml(friends)
friends.to_yaml
open('friends.yaml', 'w') do |f|
YAML.dump(friends, f)
end
end
config = Pit.get("twitter")
username = config['username']
password = config['password']
client = Rubytter.new(username, password)
friends = Array.new
last = nil
begin
last = client.friends(username, :cursor => last ? last.next_cursor : -1)
friends.concat(last.users)
rescue Timeout::Error, StandardError
puts "print Timeout::Error, StandardError"
break
end until last.next_cursor == 0
toYaml(friends)
toCsv(friends)
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require 'rubygems'
require 'pit'
require 'rubytter'
require 'yaml'
require 'pp'
# あらかじめ保存してあるフォロー一覧を取る
file = 'friends.yaml'
friends = YAML.load_file(file)
# 読んだことのある自分のフォロー
writers_names =
["arton",
"tdtds",
"spiegel_2007",
"arika",
"m_seki",
"kazuyo_k",
"fdiary",
"takahashim",
"yhara",
"takaokouji",
"wakatono",
"ikunya",
"mhatta",
"h12o",
"eto",
"freedomcat",
"kakutani",
"hyuki",
"tsuda",
"jkondo",
"kdmsnr",
"seiji_ohsaka",
"yugui",
"SekoHiroshige",
"ogawaissui",
"hazuma",
"machu",
"kasoken",
"yuasamakoto",
"Ryosuke_Nishida",
"hamano_satoshi",
"darashi",
"ShinyaMatsuura",
"mrkn",
"snoozer05",
"dambiyori",
"yomoyomo",
"yukihiro_matz",
"coco_n"
]
# screen_name から Twitterの"id"を取得
writers_ids = Array.new
writers_names.each do |writer_name|
friends.each do |user|
if writer_name == user['screen_name']
writers_ids << user['id']
end
end
end
# 自分が読者であるフォローのリストを作成
pp config = Pit.get("twitter")
username = config['username']
password = config['password']
begin
client = Rubytter.new(username, password)
pp client
client.create_list('i-read-the-books-you-written', :mode => 'public')
writers_ids.each do |id|
client.add_member_to_list("i-read-the-books-you-written", id)
end
rescue => e
puts e
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment