Skip to content

Commit

Permalink
チャンネル登録者数の投稿スクリプトを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
karia committed Sep 20, 2019
1 parent 8917ebb commit 1e028d1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem "twitter"
gem 'yt', '~> 0.29.1'
16 changes: 16 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (6.0.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.1, >= 2.1.8)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
buftok (0.2.0)
concurrent-ruby (1.1.5)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
equalizer (0.0.11)
Expand All @@ -16,8 +23,11 @@ GEM
domain_name (~> 0.5)
http-form_data (2.1.1)
http_parser.rb (0.6.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
minitest (5.11.3)
multipart-post (2.1.1)
naught (1.1.0)
public_suffix (4.0.1)
Expand All @@ -34,15 +44,21 @@ GEM
multipart-post (~> 2.0)
naught (~> 1.0)
simple_oauth (~> 0.3.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.6)
yt (0.29.1)
activesupport
zeitwerk (2.1.10)

PLATFORMS
ruby

DEPENDENCIES
twitter
yt (~> 0.29.1)

BUNDLED WITH
1.17.2
34 changes: 34 additions & 0 deletions post-number.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'twitter'
require 'yt'

client = Twitter::REST::Client.new do |conf|
conf.consumer_key = ENV['TWITTER_CONSUMER_KEY']
conf.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
conf.access_token = ENV['TWITTER_ACCESS_TOKEN']
conf.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET']
end

Yt.configuration.api_key = ENV['YOUTUBE_API_KEY']
channel_id = ARGV[0]

#登録者数取得
channel = Yt::Channel.new(id: channel_id)
number = channel.subscriber_count

#URL組み立て
item = "ミコちゃんのYouTubeチャンネル登録者数: " + number.to_s + " (" + Time.now.strftime("%m/%d %H:%M").to_s + "現在)"

#Tweetする
if number >= 50000
client.update(item)
puts "[ツイートしました]" + item
else
puts item
end

list_file = "/var/tmp/number_" + channel_id + ".txt"
# 数字を保存
File.open(list_file, "w") do |f|
f.puts(number)
end

0 comments on commit 1e028d1

Please sign in to comment.