Last active
September 28, 2015 13:48
-
-
Save motoso/dd2a5f2797db5a6c5a83 to your computer and use it in GitHub Desktop.
Twitter bot on Heroku
This file contains 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
require 'rubygems' | |
require 'sinatra' | |
require_relative './tweet.rb' | |
get '/' do | |
"under construction" | |
end | |
get '/random_tweet' do | |
# Tweet.new.random_tweet # 動作チェックが終わったらコメントアウトすること | |
end |
This file contains 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
require_relative './app.rb' | |
run Sinatra::Application |
This file contains 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
ruby '2.1.4' | |
source 'https://rubygems.org' | |
gem 'sinatra' | |
gem 'twitter' |
This file contains 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
require_relative './tweet.rb' | |
Tweet.new.daily_tweet |
This file contains 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
require 'rubygems' | |
require 'twitter' | |
class Tweet | |
def initialize | |
@text = <<-EOF.split("\n") | |
# ここに31行分のテキストを入れる | |
EOF | |
@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_SECRET' | |
end | |
end | |
def random_tweet | |
tweet = @text[rand(@text.length)] | |
update(tweet) | |
end | |
def daily_tweet | |
tweet = @text[Time.now.day - 1] | |
update(tweet) | |
end | |
private | |
def update(tweet) | |
return nil unless tweet | |
begin | |
@client.update(tweet.chomp) | |
rescue => ex | |
nil # todo | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment