Contenu connexe
Similaire à アニメの公式アカウントのフォロワー数をつぶやくTwitterボットを作ってみた (20)
Plus de Yoshitake Takata (13)
アニメの公式アカウントのフォロワー数をつぶやくTwitterボットを作ってみた
- 10. メインスクリプト(1)
#!/usr/bin/env ruby
require 'twitter'
require 'dotenv'
Dotenv.load
@client = Twitter::REST::Client.new(
:consumer_key => ENV["TWITTER_CONSUMER_KEY"],
:consumer_secret => ENV["TWITTER_CONSUMER_SECRET"],
:access_token => ENV["TWITTER_ACCESS_TOKEN"],
:access_token_secret => ENV["TWITTER_ACCESS_TOKEN_SECRET"]
)
user_account = "POPIN_Q_staff"
user = @client.user(user_account)
followers_count = user.followers_count
head = "ポッピンQ 公式ツイッターアカウント フォロワー数 "
tail = " #ポッピンQ http://www.popin-q.com/special/icon_present/"
msg = ""
filename = "followers_count_" << user_account << ".txt"
yesterday_count = File.read(filename , :encoding => Encoding::UTF_8).to_i
- 11. メインスクリプト(2)
if (followers_count <= yesterday_count) || (yesterday_count >= 3800) then
msg = ""
elsif (followers_count < 3400) then
msg = "小夏ちゃんアイコンプレゼント 3400ポッピン(フォロワー)達成まで、あと " << (3400 - followers_count).to_s
elsif (yesterday_count < 3400) && (followers_count >= 3400) then
msg = "小夏ちゃんアイコンプレゼント 3400ポッピン(フォロワー)達成おめでとう!"
elsif (followers_count < 3600) then
msg = "あさひちゃんアイコンプレゼント 3600ポッピン(フォロワー)達成まで、あと " << (3600 - followers_count).to_s
elsif (yesterday_count < 3600) && (followers_count >= 3600) then
msg = "あさひちゃんアイコンプレゼント 3600ポッピン(フォロワー)達成おめでとう!"
elsif (followers_count < 3800) then
msg = "沙紀ちゃんアイコンプレゼント 3800ポッピン(フォロワー)達成まで、あと " << (3800 - followers_count).to_s
elsif (yesterday_count < 3800) && (followers_count >= 3600) then
msg = "沙紀ちゃんアイコンプレゼント 3800ポッピン(フォロワー)達成おめでとう!"
end
if msg != "" then
msgline = head << followers_count.to_s << " " << msg << tail
print msgline
@client.update(msgline)
File.write(filename, followers_count)
end