Skip to content

Instantly share code, notes, and snippets.

@jacoyutorius
Created December 31, 2013 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacoyutorius/8191074 to your computer and use it in GitHub Desktop.
Save jacoyutorius/8191074 to your computer and use it in GitHub Desktop.
TweetをJSON形式で保存するコード
require "rubygems"
require "twitter"
require "pp"
require "logger"
require "uri"
require "json"
class Ninja
USER_ID = "NJSLYR"
TWEET_COUNT = 200
def initialize
@client = Twitter::REST::Client.new do |config|
config.consumer_key = "YOUR_CONSUMER_KEY"
config.consumer_secret = "YOUR_CONSUMER_SECRET"
config.access_token = "YOUR_ACCESS_TOKEN"
config.access_token_secret = "YOUR_ACCESS_TOKEN_SECRET"
end
end
def timeline
@client.user_timeline(USER_ID, {:count => TWEET_COUNT, :include_rts => false})
end
end
log = Logger.new("./log.log")
log.level = Logger::DEBUG
begin
# OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
ninja = Ninja.new
ar = []
ninja.timeline.each do |tweet|
ar << {:id => tweet.id, :text => URI.decode(tweet.text)}
end
pp ar
File.open("./tweet.json", "w"){|f| f.write ar.to_json}
rescue => err
log.fatal("Caught exception")
log.fatal err.backtrace.join("\n")
p err.backtrace
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment