Last active
December 16, 2015 15:49
-
-
Save rinx/5458680 to your computer and use it in GitHub Desktop.
userstreamで1000postを取得するだけ
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
#-*- 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
環境変数にCK/CS/AT/ASを設定して実行