Skip to content

Instantly share code, notes, and snippets.

@AKB428
Last active November 9, 2015 16:33
Show Gist options
  • Save AKB428/a36f89b317ade92b9a8f to your computer and use it in GitHub Desktop.
Save AKB428/a36f89b317ade92b9a8f to your computer and use it in GitHub Desktop.
放映中のアニメ公式 Twitterアカウントのフォロワー変動履歴情報を提供するRESTful API サーバーを作りました ref: http://qiita.com/AKB428/items/c12c70b16c924a45f73f
curl -v http://api.moemoe.tokyo/anime/v1/twitter/follower/status?accounts=usagi_anime,kinmosa_anime,aldnoahzero | jq .
{
"aldnoahzero": {
"updated_at": 1432364949,
"follower": 51055
},
"usagi_anime": {
"updated_at": 1411466007,
"follower": 51345
},
"kinmosa_anime": {
"updated_at": 1432364961,
"follower": 57350
}
}
ketsuekigatakun 5659
anime_lance 8685
DwD_info 22470
g_tekketsu 35960
DDhokuto_anime 2572
owarino_seraph 95786
anime_kagewani 1625
te_kyu 12599
rainy_cocoa 4224
hokuto_15aji 11417
fafnerproject 29933
Anime_W_Trigger 41316
onsenyosei 2685
usagi_anime 134950
ho_anime 7633
f_noitamina 12723
nisioisin_anime 131155
hstar_mu 26364
cometlucifer 8161
anime_kyojinchu 30973
SakurakoKujo 10738
UtawareOfficial 14501
shinmaimaou 14722
animehaikyu_com 286058
anime_yuruyuri 92904
ittoshura 15200
anime_k11 92573
opm_anime 52513
animekindaichiR 5132
ariaAA_anime 11440
asterisk_war 15870
anime_syomin 11946
35shoutai_info 7946
anime_somera 2553
Hackadoll_anime 7120
lupinIII_4th 20991
anime_dialover 68508
conrevoinfo 8273
anime_ybj 9113
valkyriedrive 6383
komori_anime 2570
noragami_PR 81402
osomatsu_PR 129156
bundle exe ruby follower_history.rb usagi_anime
bundle exe ruby follower_history.rb usagi_anime 1446901208
134964 2015-11-10 00:30:07 1447083007
134942 2015-11-10 00:00:07 1447081207
134924 2015-11-09 23:30:06 1447079406
134900 2015-11-09 23:00:07 1447077607
134882 2015-11-09 22:30:07 1447075807
134868 2015-11-09 22:00:07 1447074007
134851 2015-11-09 21:30:06 1447072206
134838 2015-11-09 21:00:07 1447070407
134824 2015-11-09 20:30:06 1447068606
134809 2015-11-09 20:00:06 1447066806
134791 2015-11-09 19:30:07 1447065007
134766 2015-11-09 19:00:06 1447063206
134759 2015-11-09 18:30:07 1447061407
134755 2015-11-09 18:00:07 1447059607
134747 2015-11-09 17:30:06 1447057806
134745 2015-11-09 17:00:06 1447056006
134741 2015-11-09 16:30:06 1447054206
134734 2015-11-09 16:00:07 1447052407
134730 2015-11-09 15:30:07 1447050607
134724 2015-11-09 15:00:06 1447048806
134720 2015-11-09 14:30:06 1447047006
134718 2015-11-09 14:00:07 1447045207
134718 2015-11-09 13:30:06 1447043406
134715 2015-11-09 13:00:06 1447041606
134711 2015-11-09 12:30:06 1447039806
134712 2015-11-09 12:00:06 1447038006
curl -v http://api.moemoe.tokyo/anime/v1/twitter/follower/history?account=usagi_anime | jq .
[
{
"updated_at": 1411466007,
"follower": 51345
},
{
"updated_at": 1410674102,
"follower": 50606
},
{
"updated_at": 1410673804,
"follower": 50607
},
{
"updated_at": 1407743045,
"follower": 46350
}
]
curl "http://api.moemoe.tokyo/anime/v1/twitter/follower/history?account=usagi_anime&end_date=1407562541" | jq .
[
{
"updated_at": 1407560663,
"follower": 46165
},
{
"updated_at": 1407558786,
"follower": 46166
},
{
"updated_at": 1407556908,
"follower": 46162
}
]
require 'net/http'
require 'uri'
require 'json'
require 'httpclient'
module Shangrila
class Sana
URL = 'http://api.moemoe.tokyo/anime/v1/twitter'
def initialize
end
# @param [Array] accounts データ取得対象のアニメTwitter公式アカウント
# @return [Hash] アカウント群をキーとしたハッシュ
def follower_status(accounts)
response = HTTPClient.get(sprintf('%s/follower/status?accounts=%s', URL, accounts.join(',')))
JSON.load(response.body)
end
# @param [Array] account データ取得対象のアニメTwitter公式アカウント
# @param [int] end_date 検索対象の終了日時 where update_at < end_date)
# @return [Array] フォロワー数と更新日時のハッシュの配列
def follower_history(account, end_date = nil)
response = nil
if end_date.nil?
response = HTTPClient.get(sprintf('%s/follower/history?account=%s', URL, account))
else
response = HTTPClient.get(sprintf('%s/follower/history?account=%s&end_date=%d', URL, account, end_date))
end
JSON.load(response.body)
end
end
end
bundle exe ruby follower_status.rb 2015 4
require 'shangrila'
account = ARGV[0]
end_date_unixtimestamp = ARGV[1]
#指定したアカウントのフォロワー履歴を取得
history_list = Shangrila::Sana.new().follower_history(account, end_date_unixtimestamp)
history_list.each do |history|
puts sprintf('%d %s %d', history['follower'], Time.at(history['updated_at']).strftime('%Y-%m-%d %H:%M:%S'), history['updated_at'] )
end
require 'shangrila'
year = ARGV[0]
cours = ARGV[1]
# 指定した年、クールのアニメ公式Twitterアカウントを取得(Sora[Master] API)
master = Shangrila::Sora.new().get_flat_data(year, cours, ['twitter_account'])
twitter_account_list = master.flatten
# 指定したTwitterアカウントのフォロワー数を取得(Sana[Twitter] API)
follower_status = Shangrila::Sana.new().follower_status(twitter_account_list)
follower_status.each do |key,val|
puts sprintf('%20s %d', key, val['follower'])
end
# A sample Gemfile
source "https://rubygems.org"
gem 'shangrila'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment