Last active
April 27, 2022 05:09
-
-
Save pooza/5812423748760190ac041f07f3215916 to your computer and use it in GitHub Desktop.
「ダイの大冒険」に関連した記念日を標準出力に出力。tomato-shriekerと組み合わせ、BOT化可能。
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
#!/usr/bin/env ruby | |
dir = File.expand_path('..', __dir__) | |
$LOAD_PATH.unshift(File.join(dir, 'app/lib')) | |
ENV['BUNDLE_GEMFILE'] = File.join(dir, 'Gemfile') | |
CHARACTER_URL = 'https://mstdn.delmulin.com/api/character/v1/detail.json'.freeze | |
ANNIVERSARY_URL = 'https://mstdn.delmulin.com/api/anniversary/v1/common.json'.freeze | |
require 'tomato_shrieker' | |
module TomatoShrieker | |
today = ARGV.first || Date.today.strftime('%m%d') | |
http = HTTP.new | |
calendar = {} | |
characters = JSON.parse(http.get(CHARACTER_URL).body) | |
characters.select {|v| v['old_cv_birthday'] && !v['old_cv_deathday']}.each do |entry| | |
key = Date.parse("2000/#{entry['old_cv_birthday']}").strftime('%m%d') | |
calendar[key] ||= [] | |
calendar[key].push(name: entry['old_cv'], prefix: '旧', character: entry['character'], type: '誕生日') | |
end | |
characters.select {|v| v['old_cv_deathday']}.each do |entry| | |
key = Date.parse("2000/#{entry['old_cv_deathday']}").strftime('%m%d') | |
calendar[key] ||= [] | |
calendar[key].push(name: entry['old_cv'], prefix: '旧', character: entry['character'], type: '命日') | |
end | |
characters.select {|v| v['new_cv_birthday'] && !v['new_cv_deathday']}.each do |entry| | |
key = Date.parse("2000/#{entry['new_cv_birthday']}").strftime('%m%d') | |
calendar[key] ||= [] | |
calendar[key].push(name: entry['new_cv'], character: entry['character'], type: '誕生日') | |
end | |
characters.select {|v| v['new_cv_deathday']}.each do |entry| | |
key = Date.parse("2000/#{entry['new_cv_deathday']}").strftime('%m%d') | |
calendar[key] ||= [] | |
calendar[key].push(name: entry['new_cv'], character: entry['character'], type: '命日') | |
end | |
calendar.each do |_d, entries| | |
entries.each do |entry| | |
entry[:name].gsub!(/\s/, '') | |
entry[:message] = '%s「%s」役 %sさんの%s' % [ | |
entry[:prefix], | |
entry[:character], | |
entry[:name], | |
entry[:type], | |
] | |
case entry[:type] | |
when '誕生日' | |
entry[:tags] = [ | |
'生誕祭', | |
(entry[:name]).to_s, | |
(entry[:character]).to_s, | |
"#{entry[:name]}生誕祭", | |
"#{entry[:name]}生誕祭#{Date.today.year}", | |
] | |
else | |
entry[:tags] = [ | |
(entry[:name]).to_s, | |
(entry[:character]).to_s, | |
] | |
end | |
entry.delete(:name) | |
entry.delete(:character) | |
entry.delete(:prefix) | |
entry.delete(:type) | |
end | |
end | |
JSON.parse(http.get(ANNIVERSARY_URL).body).each do |entry| | |
key = Date.parse("2000/#{entry['date']}").strftime('%m%d') | |
tags = entry['tags'] || [] | |
if tag = tags.find {|v| v.end_with?('生誕祭')} | |
tags.push('生誕祭') | |
tags.push("#{tag}#{Date.today.year}") | |
end | |
calendar[key] ||= [] | |
calendar[key].push(message: entry['title'], tags: tags.uniq) | |
end | |
calendar = calendar.sort.to_h | |
body = [] | |
(calendar.find {|k, _v| k == today}&.dig(1) || []).each do |entry| | |
body.push("#{today[0..1].to_i}月#{today[2..3].to_i}日は、#{entry[:message]}。\n#{entry[:tags].map(&:to_hashtag).join(' ')}") | |
end | |
puts body.join("\n=====\n") if body.present? | |
rescue => e | |
warn e.message | |
exit 1 | |
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
sources: | |
- id: dai_anniv | |
source: | |
command: | |
- bin/dai_anniv.rb | |
dir: /usr/home/pooza/repos/tomato-shrieker | |
schedule: | |
cron: '1 0 * * *' | |
dest: | |
account: | |
bot: true | |
hooks: | |
- https://mstdn.delmulin.com/mulukhiya/webhook/xxxxx | |
tags: | |
- ダイの大冒険 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
もう更新してない。今後はこっちへ。
https://github.com/pooza/dqdai-anniv