Skip to content

Instantly share code, notes, and snippets.

@rinx
Last active December 16, 2015 15:49
Show Gist options
  • Save rinx/5458680 to your computer and use it in GitHub Desktop.
Save rinx/5458680 to your computer and use it in GitHub Desktop.
userstreamで1000postを取得するだけ
#-*- coding: utf-8 -*-
require 'userstream'
# --- define consts ---
CONSUMER_KEY = ENV['CONSUMER_KEY']
CONSUMER_SECRET = ENV['CONSUMER_SECRET']
ACCESS_TOKEN = ENV['ACCESS_TOKEN']
ACCESS_SECRET = ENV['ACCESS_SECRET']
LIMIT = 1000
# --- main ---
UserStream.configure do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.oauth_token = ACCESS_TOKEN
config.oauth_token_secret = ACCESS_SECRET
end
tweets = "screen_name, name, icon, statuses_count, text, created_at, via\n"
twCount = 0
UserStream.client.user do |status|
if twCount >= 1 then
tweets += status.user.screen_name.to_s + ", "
tweets += status.user.name.to_s + ", "
tweets += status.user.profile_image_url.to_s + ", "
tweets += status.user.statuses_count.to_s + ", "
tweets += status.text.to_s + ", "
tweets += status.created_at.to_s + ", "
tweets += status.source.to_s
tweets += "\n"
end
twCount += 1
if twCount >= LIMIT then
break
end
end
File.write("tweets.csv", tweets)
@rinx
Copy link
Author

rinx commented Apr 25, 2013

環境変数にCK/CS/AT/ASを設定して実行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment